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
Organizations can face criminal or civil penalties for being ______ in protecting their sensitive data.
MakcuM [25]
The answer to this question is A. hope this helped thanks.
6 0
3 years ago
Read 2 more answers
What safety feature melts to protect a circuit? a. fuse b. diode c. three-prong plug d. transistor
babunello [35]
The correct answer is A. fuse.
8 0
3 years ago
Read 2 more answers
Whe you read anything online how do you know whether or not is coming from a reliable source?
lorasvet [3.4K]

You can find the author and research his/her credibility

You can cross-reference the information to other documentations

You can investigate the credibility of the overall website or community. Teachers like to say that community sites like wikipedia aren't very reliable.

4 0
3 years ago
Read 2 more answers
What is the biggest difference between technical communication and the other kinds of writing you have done?
lukranit [14]

Answer:

 The main difference between the technical communication and the other different kinds of communication is that as follow:

  • In technical communication, the data or information must be specific and to the point. On the other hand, in general communication there is no such boundary for the conversation.
  • The content of the technical conversation should be in proper and systematic format and in general communication there is no such formatting required.
  • The technical communication always focus on the audience and main purpose of the conversation as compared to general communication.

3 0
3 years ago
3 Points
gulaghasi [49]

Answer: Well, In my Opinion it would Be D! because these day people stick together with the internet!. If she adopt her Online business then she would be able to earn profits and also she can serve the people! Slowly people will get to know her business! That will be good for her!

<h3>I hope this works! :)</h3>

3 0
3 years ago
Other questions:
  • A species of snake lives in a rainforest. Which would be an adaptation for this
    10·2 answers
  • C. to which cache block will the memory address 0x000063fa map
    14·1 answer
  • The number of pixels displayed on the screen is known as ________.
    14·1 answer
  • Which of the following keys open the spelling and Grammer dialog box
    6·1 answer
  • Given two variables , first_place_winner and second_place_winner, write some code that swaps their associated values. use any ad
    12·1 answer
  • 4.8 Code Practice: Question 1<br> I need help
    13·1 answer
  • Write method reverseString, which takes a string str and returns a new string with the characters in str in reverse order. For e
    8·1 answer
  • As you explore career options why is it important to take personal inventories and assessments
    5·2 answers
  • In java complete a program that takes a weight in kilograms as input, converts the weight to pounds, and then outputs the weight
    15·1 answer
  • What is the current situation of drone technology in emergency rescue and recovery
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!