Question

4) Write a Java program using Conditions: Write a program where it will ask user to...

4) Write a Java program using Conditions: Write a program where it will ask user to enter a number and after that it will give you answer how many digits that number has.

Steps: 1) Create Scanner object and prompt user to enter the number and declare variable integer for input

2) Use if else condition with && condition where you will specify the digits of numbers by writing yourself the digit number that should display: Example(num<100 && num>=1), and so on

3) After using if else statement for any possibility in the end just declare that number is not between 1 and 99999

4) Output condition should look something like this:

OUTPUT EXAMPLE:

Enter a number:

56891

It’s a five digit number

Homework Answers

Answer #1

Have a look at the below code. Its quite intutive to understand.

import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    System.out.println("Enter the number");

    int number = sc.nextInt();

    if (number>=1 && number<=9){
      System.out.println("It’s a one digit number");
    }
    else if(number>=10 && number<=99){

      System.out.println("It’s a two digit number");

    }

    else if(number>=100 && number<=999){

      System.out.println("It’s a three digit number");

    }

     else if(number>=1000 && number<=9999){

      System.out.println("It’s a four digit number");

    }

     else if(number>=10000 && number<=99999){

      System.out.println("It’s a five digit number");

    }

    // Like this you can ad as many conditions as per your requirement...
  }
}

Happy Learning!

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
5) Create a Java program using Scanner: Write a program where you will enter the grade...
5) Create a Java program using Scanner: Write a program where you will enter the grade score for 5 classes, then it will display total points and average and it will display the grade based on percentage. Steps: 1) Declare variable integer for English, Chemistry, Java Programming, Physics and Math 2) Declare variable total and percentage 3) Create Scanner object and prompt the user to enter grades for each class and input grades after each class 4) Calculate total of...
1) Write a java programming using a while loop where you will add numbers and when...
1) Write a java programming using a while loop where you will add numbers and when you press number 0 it will add all your numbers and display the results. Use Scanner object. Steps: 1) Declare variables integer called sum which is equal to zero   2) Declare Scanner object   3) Declare while condition where is true   4) Inside of that condition prompt the user to enter the numbers   5) Declare variable integer called number and input the number statement   6)...
Write a Java program called Decision that includes a while loop to prompt the user to...
Write a Java program called Decision that includes a while loop to prompt the user to enter 5 marks using the JOptionPane statement and a System. Out statement to output a message inside the loop highlighting a pass mark >= 50 and <= 100. Any other mark will output a messaging stating it’s a fail. Example of the expected output is as follows:
Write a program in Java where a user of this program will play a game in...
Write a program in Java where a user of this program will play a game in which he/she needs to guess a target number, which is a number that the program has randomly picked in the range that the user chooses. The program will repeatedly prompt for the guessed number and provide a clue whether the guessed number is bigger or smaller than the target number, until the guessed number equals the target number.
The Java program should sum the odd integers from 1 to the integer that the user...
The Java program should sum the odd integers from 1 to the integer that the user enters. For example, if the user enters 30, the program should sum the odd integers from 1 to 30.   Print "Please enter a positive nonzero integer." Declare a Scanner and obtain an integer from the user.   Use a Do...while statement and calculate the sum Use the integer that the obtained from the previous step for the loop-continuation condition. Display the sum Print the sum...
IN C++ PLEASE. Write a program where the user enters a number and you output an...
IN C++ PLEASE. Write a program where the user enters a number and you output an unfilled square of stars. (DO NOT PROMPT THE USER, just take in a number, The only console output should be the squares). For example the program would start with console input, The user would enters 3, you would output (note 3 is the lowest number your program will be tested with) *** * * *** or, The user enters 5, you would output *****...
Please use Python 3 4). Write a program that asks the user to enter 10 numbers....
Please use Python 3 4). Write a program that asks the user to enter 10 numbers. The program should store the numbers in a list and then display the following data: • The lowest number in the list • The highest number in the list •The total of the numbers in the list • The average of the numbers in the list   Sample input & output: (Prompt) Enter Number 1: (User enter) 4 (Prompt) Enter Number 2: (User enter) 7...
design a program that prompts the user to enter a positive integer number and reads the...
design a program that prompts the user to enter a positive integer number and reads the user’s input. If the user input is not a positive number, the program should prompt them repeatedly until they enter a valid input. Once a valid input is received ,the program uses a loop to calculate the sum of the digits of the user’s input and displays the sum. For example, if the user enters the number 94311, the program should print the sum...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even...
8.39 Lab 8d: Even Entry Loop This program will ask the user to enter an even number and continue to do so until they enter the given QUIT condition. The prompt for the user to enter a number is written as follows: "Enter an even number or [QUIT] to quit:" The quitting condition in this case will be the number 999. If the number they entered was an even number, output the message "Good job!" Otherwise, output the message "[number]...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive...
4) Create the following in a Java program. Create a Scanner Prompt the user to Receive the amount and declare the variable double amount for scanner Declare variable integer remaining amount which is equal to (int) (amount*100) Find the number of one dollars bt declaring the integer variable which is equal to remaining amount divided by 100 Declare: remaining amount %=100 Find the number of quarters: Declare integer variable number of quarters equal to remaining amount divided by 25 Declare:...