Question

Write a do-while loop that continues to prompt a user to enter a number less than...

Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with newline Ex: For the user input 123, 395, 25, the expected output is:
Enter a number (<100): 
Enter a number (<100): 
Enter a number (<100): 
Your number < 100 is: 25

import java.util.Scanner;

public class NumberPrompt {
public static void main (String [] args) {
Scanner scnr = new Scanner(System.in);
int userInput = 0;

/* Your solution goes here */

System.out.println("Your number < 100 is: " + userInput);

return;
}
}

0 1
Add a comment Improve this question Transcribed image text
✔ Recommended Answer
Answer #1

Screenshot of the code:

port java.util.Scanner; im //Declare the class NumberPrompt public class NumberPrompt public static void main(String args [])

Sample Output:

Enter a number (<100) 123 Enter a number (<100) 395 Enter a number (<100) 25 Your number <100 is 25

Code to copy:

import java.util.Scanner;

//Declare the class NumberPrompt.

public class NumberPrompt

{

   public static void main(String args[])

   {

        /*Declare the variable of scanner class and allocate the

        memory.*/

        Scanner scnr = new Scanner(System.in);

       

        //Initialize the variable userInput.

        int userInput = 0;

        /* Your solution goes here*/

        //Start the do-while loop

        do

        {

          //Prompt the user to enter the number.

          System.out.println("Enter a number(<100)");

         

          /*Store the number entered by the user in the

          variable userInput.*/

          userInput=scnr.nextInt();

            

        }while(userInput>=100);/*Run the do-while loop till the    

        user input is greater than 100*/

       

        //Print the number which is less than 100.

        System.out.println("Your number <100 is "+userInput);

        return;

   }

}

Add a comment
Know the answer?
Add Answer to:
Write a do-while loop that continues to prompt a user to enter a number less than...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Similar Homework Help Questions
  • Write a do-while loop that continues to prompt a user to enter a number less than...

    Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 c++ #include using namespace std; int main() { int userInput = 0; do cout << "Your number <...

  • C++ Program Write a do-while loop that continues to prompt a user to enter a number...

    C++ Program Write a do-while loop that continues to prompt a user to enter a number less than 100, until the entered number is actually less than 100. End each prompt with a newline. Ex: For the user input 123, 395, 25, the expected output is: Enter a number (<100): Enter a number (<100): Enter a number (<100): Your number < 100 is: 25 #include <iostream> using namespace std; int main() { int userInput; /* Your solution goes here */...

  • Write an expression that executes the loop while the user enters a number greater than or...

    Write an expression that executes the loop while the user enters a number greater than or equal to 0. Note: These activities may test code with different test values. This activity will perform three tests, with user input of 9, 5, 2, -1, then with user input of 0, -17, then with user input of 0 1 0 -1. Also note: If the submitted code has an infinite loop, the system will stop running the code after a few seconds,...

  • Complete the do-while loop to output 0 to countLimit. Assume the user will only input a...

    Complete the do-while loop to output 0 to countLimit. Assume the user will only input a positive number. import java.util.Scanner; public class CountToLimit { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int countLimit = 0; int printVal = 0; // Get user input countLimit = scnr.nextInt(); printVal = 0; do { System.out.print(printVal + " "); printVal = printVal + 1; } while ( /* Your solution goes here */ ); System.out.println(""); return; } }

  • Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for...

    Answer in JAVA 1. Complete the method definition to output the hours given minutes. Output for sample program: 3.5 import java.util.Scanner; public class HourToMinConv {    public static void outputMinutesAsHours(double origMinutes) {       /* Your solution goes here */    }    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       double minutes;       minutes = scnr.nextDouble();       outputMinutesAsHours(minutes); // Will be run with 210.0, 3600.0, and 0.0.       System.out.println("");    } } 2....

  • CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to...

    CHALLENGE ACTIVITY 3.11.1: Using boolean. D Assign is Teenager with true if kidAge is 13 to 19 inclusive. Otherwise, assign is Teenager with false. 1 import java.util.Scanner; 3 public class TeenagerDetector 1 public static void main (String [] args) { Scanner scnr = new Scanner(System.in); boolean isTeenager; int kidAge; D}]oll kidage = scnr.nextInt(); /* Your solution goes here */ Go USB if (isTeenager) { System.out.println("Teen"); else { System.out.println("Not teen"); 20 Run Feedback? CHALLENGE ACTIVITY 3.11.2: Boolean in branching statements. Write...

  • Write a while loop that prints all positive numbers that are divisible by 10 and less...

    Write a while loop that prints all positive numbers that are divisible by 10 and less than a given number n. For example, if n is 100, print 10 20 30 40 50 60 70 80 90. import java.util.Scanner; public class PositiveLess {    public static void main(String[] args) {        Scanner in = new Scanner(System.in);        System.out.print("n: ");        int n = in.nextInt();        ...        while (...)        {           ...

  • Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a...

    Write a for loop to print all NUM_VALS elements of array hourlyTemp. Separate elements with a comma and space. Ex: If hourlyTemp = {90, 92, 94, 95}, print: 90, 92, 94, 95 Your code's output should end with the last element, without a subsequent comma, space, or newline. import java.util.Scanner; public class PrintWithComma {    public static void main (String [] args) {       Scanner scnr = new Scanner(System.in);       final int NUM_VALS = 4;       int[] hourlyTemp = new...

  • Print 'Censored if userinput contains the word"darn', else print userinput End with newline. Ex iIf userinput...

    Print 'Censored if userinput contains the word"darn', else print userinput End with newline. Ex: if userinput is "That darn cat.:. then output is: Censored Ex: If userinput is Dang, that was scaryl", then output is: Dang, that was scary Note: If the submitted code has an out-of-range access, the system will stop running the code after a few seconds, and report Program end never reached The system doesn't print the test case that caused the reported message. import java.util.Scanner; public class Censoredwords {public static...

  • CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99,...

    CHALLENGE ACTIVITY 3.5.1: Detect specific values. Write an expression that prints "Special number if specialNum is-99, 0, or 44. 1 import java.util.Scanner; 3 public class Find SpecialValue { public static void main (String [] args) { Scanner scnr = new Scanner(System.in); int specialNum; specialNum - scnr.nextInt(); POSLOVOU if (/* Your solution goes here */) { System.out.println("Special number"); else { System.out.println("Not special number"); Run View your last submission

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT