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
Change the screen resolution so you can view more information on your screen. Use the resolution that enables you to fit the mos
bulgar [2K]
On Windows 10, you are able to right-click the desktop, and select "Display Settings". From there you can see all attached displays that are connected to your computer. Select "Advanced display settings", and your resolution would be right there, for example, the resolution of my monitor is 3840×2160.
4 0
3 years ago
within the data set hrd.temp, payrate is a numeric variable and hours is a character variable. what happens when the following p
Fantom [35]
  • SAS converts the PayRate value to a numeric value form; a message is written in the form of a log

  • SAS can be defined a comprehensive statistical software that provides a wide variety of analytical capabilities, data management, and visualization options

   

  • Compare between SAS and Python

Python is a high-level programming language, more object-oriented, and is known by all programmers.

In addition, python also includes a modern programming language.

Python is a programming language that has evolved from previous programming languages.

But in terms of learning, SAS is a programming language that is easier to follow compared to python.

These are the advantages and disadvantages of each programming language

Learn more about programming language here brainly.com/question/23959041

#SPJ1

6 0
2 years ago
Inter-enterprise pride systems are referred to as ________ because in such systems processing is divided across multiple computi
vredina [299]
<span>Inter-enterprise PRIDE systems are referred to as distrubbuted systems because in such systems processing is divided across multiple computing devices.</span>
7 0
3 years ago
Mr. Cooper would like to customize his Excel software so his students can create an electronic graph in Excel for their lab repo
Neko [114]
The third one probably
5 0
4 years ago
I need help ASAP please and thank you!
S_A_V [24]

Answer:

Explanation: For the best approach, It would say Option 3, you're supporting the waiter and making the rude customer feel as if they got what they wanted of complaining to the manager.

The worst approach I think would be Option 4, but this feels opinion based. Choose what you feel would be the best approach for this one.

6 0
3 years ago
Other questions:
  • Radio waves pros and cons
    10·2 answers
  • C. to which cache block will the memory address 0x000063fa map
    14·1 answer
  • Where can the Ease of Access and Speech Recognition centers be found?
    8·2 answers
  • Match the data type to their correct explanations,
    13·2 answers
  • An example of an "external brain" is:
    5·2 answers
  • Discuss the importance of top management commitment and the development of standards for successful project management. Provide
    10·1 answer
  • Sierra needs to ensure that when users are entering data into a datasheet or form that they are limited in the values they can s
    15·2 answers
  • Overview In this assignment, you will gain more practice with designing a program. Specifically, you will create pseudocode for
    7·1 answer
  • Write a program that keeps asking the user for new values to be added to a list until the user enters 'exit' ('exit' should NOT
    10·1 answer
  • When working in outline mode, press __________ and click the eye icon to change only one layer back to preview mode.
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!