思路:利用一个字符串来存储待判定的标识符,然后,判断第一个字符是否合法和第二到最终的字符是否合法。
代码:
**import java.util.Scanner;
public class Main1 {
public static void main(String[] args) {
Scanner reader=new Scanner(System.in);
int num=reader.nextInt();
String b=reader.nextLine();//用来接收输入int之后的回车的
for(int k=0;k<num;++k)
{
int count=0;
String a=reader.nextLine();
char c;
c=a.charAt(0);
if(c=='_'||(c>='a'&& c<='z')||(c>='A'&&c<='Z')) {}
else
{
++count;
}
for(int i=1;i<a.length();++i)
{
c=a.charAt(i);
if(c=='_'||(c>='a' && c<='z')||(c>='A' && c<='Z')||(c>='0'&&c<='9'))
{}
else
{
++count;
}
}
if(count>0)
System.out.println("no");
else
System.out.println("yes");
}
}
}
**