2017-08-13 14 views
-1

私はエラーフラグとしてinvalidFName,invalidLName,invalidStreet,invalidCity,invalidState,invalidContactNoを使用しています。奇妙なことは、invalidFNameinvalidLNameだけが「未使用」とマークされ、残りは問題ありません。ここでJava:変数が使用されていません

は、NetBeans にenter image description here

そして、ここでは私のコードだように見えるされるものです。どのような助けが大いに感謝しています:)

String fName, lName, street, city, state, contactNo; 
    boolean invalidFName, invalidLName, invalidStreet, invalidCity, invalidState, invalidContactNo; 

    do{ 
     invalidFName = true; 

     System.out.print("Please enter first name: "); 
     fName = sc.next(); 

     if (!fName.matches("^[A-Z]|[a-z]|{3,15}$")) 
      System.out.println(MSG_INVALID_HEAD + "alphabets and is between 3 and 15 characters"); 
     else 
      invalidFName = false; 

    } while(invalidFName = true); 

    do{ 
     invalidLName = true; 

     System.out.print("Please enter first name: "); 
     lName = sc.next(); 

     if (!lName.matches("^[A-Z]|[a-z]|{3,15}$")) 
      System.out.println(MSG_INVALID_HEAD + "alphabets and is between 3 and 15 characters"); 
     else 
      invalidLName = false; 

    } while(invalidLName = true); 

    System.out.println("Please enter address"); 
    do{ 
     invalidStreet = true; 

     System.out.print("Street: "); 
     street = sc.next(); 

     if(!street.matches("^[A-Z]|[a-z]|[1-9]|{1,15}$")) 
      System.out.println(MSG_INVALID_HEAD + "alphabets and numbers and is between 1 and 15 characters"); 
     else 
      invalidStreet = false; 

    } while(invalidStreet == true); 

    do{ 
     invalidCity = true; 

     System.out.print("City: "); 
     city = sc.next(); 

     if(!city.matches("^[A-Z]|[a-z]|[1-9]|{1,15}$")) 
      System.out.println(MSG_INVALID_HEAD + "alphabets and numbers and is between 1 and 15 characters"); 
     else 
      invalidCity = false; 

    } while(invalidCity == true); 

    do{ 
     invalidState = true; 

     System.out.print("State: "); 
     state = sc.next(); 

     if(!state.matches("^[A-Z]|[a-z]|[1-9]|{1,15}$")) 
      System.out.println(MSG_INVALID_HEAD + "alphabets and numbers and is between 1 and 15 characters"); 
     else 
      invalidState = false; 

    } while(invalidState == true); 

    do{ 
     invalidContactNo = true; 

     System.out.print("Contact Number: "); 
     contactNo = sc.next(); 

     if(!contactNo.matches("^[1-9]|{1,10}$")) 
      System.out.println(MSG_INVALID_HEAD + "numbers and is between 1 and 10 characters"); 
     else 
      invalidContactNo = false; 

    } while(invalidContactNo == true); 
+2

while(invalidFName == true) 'または単にwhile(invalidFName) ' – Guy

答えて

0

ああ、それは恥ずかしいルーキーエラーでした!

ソリューション -

while(invalidLName = true);

は、迅速な対応のためのガイに

while(invalidLName == true);

感謝する必要があります!

+0

はい、invalidFNameも同じエラーがあります。 –

関連する問題