import java.util.Scanner; public class CheckingPasscodes { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean hasDigit; String passCode; hasDigit = false; passCode = scnr.next(); /* Your solution goes here */ if (hasDigit) { System.out.println("Has a digit."); } else { System.out.println("Has no digit."); } } }

Respuesta :

Answer:

The correct solution to this question as follows:

code:

       //declaring integer variable  

       int x1,x2,x3;

       //holding value in variable

       x1= passCode.charAt(0); //x1 hold fist Character value

       x2= passCode.charAt(1); // x2 hold second Character value

       x3= passCode.charAt(2); // x3 hold third Character value

       //if block to check condition  

       if ((Character.isDigit(x1)||Character.isDigit(x2) || Character.isDigit(x3))) //using OR operator

       {

           hasDigit = true; //change value to true

       }        

Explanation:

In the above code first three integer variable is declared that is "x1, x2, and x3" these variable is used to hold the string variable character value. to hold character value the charAt() method is used.

  • In the class "CheckingPasscodes"  If condition block is used, that accepts above integer variable value and uses the isDigit() method, that checks the value is an integer or not, inside this block the OR logical operator is used, that executes, when all the value is true. The hasDigit variable holds a true value.
  • In the next step, another if block is used, in this block "hasDigit" variable value is check, if it is true it will print "Has a digit", otherwise it will go to else section, that will print "Has no digit".
ACCESS MORE
EDU ACCESS