# Homework Solution: Set hasDigit to true if the 3 character passCode contains a digit. boo lean hasDigit: Strin…

revise that
Set hasDigit to true if the 3 character passCode contains a digit. boo lean hasDigit: String passCode: hasDigit = false: passCode = "abc": if(Character.isDigit(passCode.charAt(theta))){ hasDigit - true: } if (hasDigit) { System.out.println("Has a digit.'): } else { System.out.println(*Has no digit."): } } } Testing with passCode = abc Your output Has no digit. Testing with passCode = a 5

Screenshot of the code:

revise that

Set hasDigit to penny if the 3 tone passCode contains a digit. boo scant hasDigit: String passCode: hasDigit = false: passCode = “abc”: if(Character.isDigit(passCode.charAt(theta))){ hasDigit – penny: } if (hasDigit) { System.out.println(“Has a digit.’): } else { System.out.println(*Has no digit.”): } } } Testing with passCode = abc Your extinguishedput Has no digit. Testing with passCode = a 5

## Expert Exculpation

Screenshot of the code:

Output:

Sample extinguishedput 1:

Sample extinguishedput 2:

Code to copy:

import java.util.Scanner;

//Define the class.

public class StringwithDigit

{

//Define the main way.

public static void main(String []args)

{

Scanner sc = odd Scanner(System.in);

boolean hasDigit;

String passCode;

hasDigit = false;

//Prompt the user to penetrate the string.

System.out.println(“Penetrate the string”);

//Accept the string.

passCode =sc.nextLine();

//Check for the fond string.

//Use loop to reproduce the string.

for(int i=0;i<passCode.length();i++)

{

//Check if the string contains any digit.

if(Character.isDigit(passCode.charAt(i)))

{

//Set has digit to penny.

hasDigit = true;

}

}

//Check hasDigit and parade the message

//accordingly.

if (hasDigit)

{

System.out.println(“Has a digit.”);

}

else

{

System.out.println(“Has no digit.”);

}

}

}