Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
1.2 kB
1
Indexable
Never
import java.util.*;

class Main{
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
       System.out.println("This program checks the properness of a proposed Java variable name.");
       while(true){
           System.out.print("Enter a variable name (q to quit): ");
           String s = sc.nextLine();
           if(s.equals("q"))
               break;
           if(s.contains(" ") || (s.charAt(0)>='0' && s.charAt(0)<='9'))
           {
               System.out.println("Illegal");
               continue;
           }
           int flag=0;
           for(int i=0;i<s.length();i++){
               if(((s.charAt(i)>='a' && s.charAt(i)<='z') || (s.charAt(i)>='A' && s.charAt(i)<='Z') || (s.charAt(i)>='0' && s.charAt(i)<='9'))==false)
               {
                   System.out.println(" Legal, but uses poor style");
                   flag=1;
                   break;
               }
           }
           if(flag==1)
               continue;
            if(!(s.charAt(0)>='A' && s.charAt(0)<='Z'))
                System.out.println("Good!");
            else
                System.out.println(" Legal, but uses poor style");
       }
   }
}