Answer to Question #204885 in Java | JSP | JSF for Vanessa

Question #204885

Set hasDigit to true if the 3-character passCode contains a digit.


1
Expert's answer
2021-06-09T04:24:27-0400


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();
	}
}




Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS