Fill This Form To Receive Instant Help

Help in Homework
trustpilot ratings
google ratings


Homework answers / question archive / In Java Set hasDigit to true if the 3-character passCode contains a digit

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

Computer Science

In Java Set hasDigit to true if the 3-character passCode contains a digit. If you could tell me why the code I wrote isn't working 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 a digit.");
}
else {
System.out.println("Has no digit.");
}
}
}

Option 1

Low Cost Option
Download this past answer in few clicks

2.85 USD

PURCHASE SOLUTION

Already member?


Option 2

Custom new solution created by our subject matter experts

GET A QUOTE