HDU - 2024 C语言合法标识符 JAVA练习

JAVA 练习 



package program;

import java.util.*;
import java.math.*;

public class Main {
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		
		int n = in.nextInt();
		in.nextLine();
		for(int j = 0; j < n; ++j) {
			String s = in.nextLine();
			boolean f = true;
			if(s.charAt(0) >= '0' && s.charAt(0) <= '9') {
				System.out.println("no");
			}
			else{
				for(int i = 0; i < s.length(); ++i) {
					if( !( (s.charAt(i) >= '0'&& s.charAt(i) <= '9' ) || (s.charAt(i) >= 'a' && s.charAt(i) <= 'z') || s.charAt(i) == '_' || (s.charAt(i) >= 'A' && s.charAt(i) <= 'Z')) ) {
						//System.out.println("no");
						f = false;
						break;
					}
				}
				if(f) System.out.println("yes");
				else System.out.println("no");
			}
			
		}
	}
}


你可能感兴趣的:(JAVA)