Question: In Java; Set hasDigit to true if the 3-character passCodecontains a digit. If you could tell me why the code I wrote isn'tworking I'd be

In Java; Set hasDigit to true if the 3-character passCodecontains a digit. If you could tell me why the code I wrote isn'tworking I'd be thankful.

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

let0 = userInput.charAt(0);
let1 = userInput.charAt(1);
let2 = userInput.charAt(2);

if ((Character.isDigit(let0) ||Character.isDigit(let1) || Character.isDigit(let2)){
hasDigit = true;
}

if (hasDigit) {
System.out.println("Has adigit.");
}
else {
System.out.println("Has nodigit.");
}
}
}

Step by Step Solution

3.35 Rating (158 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Answer and step by step explanation The code you have written is not work... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!