Question

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

Please write this in Java!


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

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 14 digit.");

else{ 

System.out.println("Has no digit.");

}

0 0
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

// CheckPasscodes.java

import java.util.Scanner;

public class CheckPasscodes {

   public static void main(String[] args) {

       /*
       * Creating an Scanner class object which is used to get the inputs
       * entered by the user
       */
       Scanner scnr = new Scanner(System.in);
       boolean hasDigit;
       String passCode;
      
       hasDigit=false;
       passCode=scnr.next();
      
       for(int i=0;i        {
           if(Character.isDigit(passCode.charAt(i)))
           {
               hasDigit=true;
               break;
           }
       }
       if(hasDigit)
       {
           System.out.println("Has digit.");
       }
       else
       {
           System.out.println("Has no digit.");
       }
      
   }

}
________________________

Output#1:

Hello5Kane
Has digit.

________________________

Output#2:

HelloKane
Has no digit.


_______________Could you plz rate me well.Thank You

Add a comment
Know the answer?
Add Answer to:
Set hasDigit to true if the 3-character passCode contains a digit.
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT