Set hasDigit to true if the 3-character passCode contains a digit.
import java.util.Scanner;
public class HasDigitProject {
/**
* The start point of the program
*
* @param args
*/
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String passCode;
boolean hasDigit=false;
System.out.print("Enter the passCode: ");
passCode=scanner.nextLine();
for(int i=0;i<passCode.length();i++) {
//Set hasDigit to true if the 3-character passCode contains a digit.
if(Character.isDigit(passCode.charAt(i))) {
hasDigit=true;
}
}
System.out.println("hasDigit: "+hasDigit);
scanner.close();
}
}
Comments
Leave a comment