1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Aleksandr-060686 [28]
3 years ago
13

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 work

ing 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.");}
Computers and Technology
1 answer:
Sever21 [200]3 years ago
6 0

Answer:

The correct program to this question can be given as:

Program:

//import package.

import java.util.Scanner; //scanner package.

public class CheckingPasscodes //define class.

{

//all the code run here.

public static void main (String [] args) //define main method

{

Scanner scnr = new Scanner(System.in); //create Scanner class Object

boolean hasDigit; //define variable.

String passCode; //define variable.

hasDigit = false; //assign value.

passCode = scnr.next(); //taking user input.

int let0 = passCode.charAt(0); //assign value in integer variable

int let1 = passCode.charAt(1); //assign value in integer variable

int let2 = passCode.charAt(2); //assign value in integer variable

//conditional statement.

if ((Character.isDigit(let0)||Character.isDigit(let1)||Character.isDigit(let2))) //if block

{

hasDigit = true; //assign value.

}

if (hasDigit) //if block

{

System.out.println("Has a digit."); //message.

}

else //else block

{

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

}

}

}

Output:

AB1

Has a digit.

Explanation:

In the given question there are many mistakes so we provide the correct solution to this question that can be described as follows:

  • In above java program firstly, we import a package that is used for taking user input. Then we define a class that is "CheckingPasscodes" in this class we define the main method. In the main method, we create a scanner class object and define some variables that are "passCode and hasDigit". A variable passCode is used for user input.
  • Then we define three integer variable that is "let0, let1, and let2".  This variable uses a charAt() function that holds the index values and assign to these variables.
  • Then we define conditional statements. In if block we check variables "let0, let1 and let2" value is equal to the number. so, we change the bool variable value that is "true".
  • In second if block we check bool variable "hasDigit" value is true. so we print "Has a digit.". else we print "Has no digit.".
You might be interested in
This is a legitimate question if you have a problem then just ignore it. What is the difference between CRVM and SAPX in a progr
g100num [7]

Answer: SAPX is used with Java

Explanation:

4 0
3 years ago
Read 2 more answers
To find resources on the Internet for your courses, you may need to use a search engine. Suppose that you are collecting informa
tekilochka [14]

Answer:

d. "Columbus, Wisconsin"

Explanation:

mark me brainliest please

8 0
3 years ago
How many 32 bit integers can be stored in 16 byte cache block in matlab?
Sladkaya [172]
Bytes have eight bits. 32 bits would be four bytes.
4 0
4 years ago
If you are interested in joining the military, you can attend college _____. a. before serving b. during service c. after servic
Arturiano [62]

D .All the above.

Explanation:while in the military you can take online courses during service or you can can choose to do it before or after

6 0
4 years ago
What type of malicious software tries to gather information about you without your consent?
AlekseyPX

Answer:

B-malware

Explanation:

I do tech and i help work on computars.

6 0
3 years ago
Other questions:
  • String word = “Awesome”;
    9·2 answers
  • Write a function decimalToBinaryRecursive that converts a decimal value to binary using recursion. This function takes a single
    11·1 answer
  • What is it called when you make a reference in the text of a document alerting the reader that you are using information from an
    10·1 answer
  • What is the best information to include in the template name to differentiate it from other templates? Check all that apply.
    6·1 answer
  • What is Java Script?
    13·1 answer
  • Where does the list of incoming mail appear in gmail
    13·2 answers
  • Hewo everyone look at me I look ugly don't I<br>​
    6·2 answers
  • Can someone write me a design brief about a stadium​
    12·2 answers
  • Write a program code which asks for 80 numbers between 100 and 1000 to be entered.
    7·1 answer
  • This feature in Word Online allows you to view your document to see what it will look like when printed.
    6·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!