私はエラーフラグとしてinvalidFName
,invalidLName
,invalidStreet
,invalidCity
,invalidState
,invalidContactNo
を使用しています。奇妙なことは、invalidFName
とinvalidLName
だけが「未使用」とマークされ、残りは問題ありません。ここでJava:変数が使用されていません
そして、ここでは私のコードだように見えるされるものです。どのような助けが大いに感謝しています:)
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);
while(invalidFName == true) 'または単にwhile(invalidFName) ' – Guy