Question

Write a java program where you will enter as many numbers as you want and, in...

Write a java program where you will enter as many numbers as you want and, in the end, when you press zero it will display the largest number.

Steps:

1) Create scanner object

2) Declare variable number and max;

3) Enter the number with prompt system

4) Declare number and input statement

5) Declare max which is equal to number (in other word any number that you enter is equal to max)

6) Declare the while condition where number is not equal to zero

7) Inside of that while brace condition declares number and his input statement

8) After that create selection if statement where number is greater than max variable

9) Declare after that, that variable max is equal to variable number

10) In the end show in print the max number Note: basically, after you enter numbers of your choice when you enter zero it should give you the largest number.

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

//The below code follows the steps exactly. However, the given steps compare zero also with the max in the end. if //you dont want zero to be compared with max in the end follow the second program

import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
   Scanner sc = new Scanner(System.in);
int number,max;
System.out.print("Enter number: ");
number=sc.nextInt();
max=number;
while(number!=0)
{
System.out.print("Enter number: ");
number=sc.nextInt();   
if(number>max)
max=number;
}
System.out.println("Max number: "+max);
   }
}

Main.java import java.util.Scanner; 2 public class Main 3 - { 4 public static void main(String[] args) 5 { 6 Scanner sc = new

// proram that doesnt include zero

import java.util.Scanner;
public class Main
{
   public static void main(String[] args)
   {
   Scanner sc = new Scanner(System.in);
int number,max;
System.out.print("Enter number: ");
number=sc.nextInt();
max=number;
while(number!=0)
{
if(number>max)
max=number;
System.out.print("Enter number: ");
number=sc.nextInt();   
}
System.out.println("Max number: "+max);
   }
}
Main.java 1 import java.util.Scanner; 2 public class Main 3- { 4 public static void main(String[] args) 5 { 6 Scanner sc = ne

Add a comment
Know the answer?
Add Answer to:
Write a java program where you will enter as many numbers as you want and, in...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class...

    // Group Names: // Date: // Program Description: //   Import required packages //--> //   Declare class (SwitchDoLab) //--> {    //   Declare the main method    //-->    {        //   Declare Constant integers SUM = 1, FACTORIAL = 2, QUIT = 3.        //-->        //-->        //-->        //   Create an integer variable named choice to store user's option.        //-->        //   Create a Scanner object        //   Create...

  • MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers....

    MATLAB QUESTION 8) Create a program that first prompts the user to enter any two numbers. Then prompt the user again to input as many numbers as they choose. Stop the program by inputting-1. Then, display the largest number and second largest number in the command window once the user kills the program. The built-in max function cannot be used. The figure below is an example of what the command window should look like when the code is ran. First...

  • Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it)...

    Java code Guessing Game Refinement. (The user thinks of a number and the program guesses it) Program should be able to guess correctly in 7 tries or lower. Initialize a variable that represents the lowest possible number to 0 (what type should this be?) Initialize a variable that represent the highest possible number to 100 (what type should this be?) Initialize a Boolean variable that represents if we’ve achieved the correct guess to false Initialize a variable in which to...

  • Write a Java program to meet the following requirements: 1. Prompt the user to enter three...

    Write a Java program to meet the following requirements: 1. Prompt the user to enter three strings by using nextLine(). Space can be part of the string). ( Note: your program requires using loop: for-loop, while-loop or do-while-loop to get the input String ) 2. Write a method with an input variable (string type).The method should return the number of lowercase letters of the input variable. 3. Get the number of the lowercase letters for each user input string by...

  • Write a program that asks the user how many integers they would like to enter. You...

    Write a program that asks the user how many integers they would like to enter. You can assume they will enter an integer >= 1. The program will then prompt the user to enter that many integers. After all the numbers have been entered, the program should display the largest and smallest of those numbers (no, you cannot use lists, or any other material we haven't covered). When you run your program it should match the following format: How many...

  • 1- Write a program to read 10 numbers and find the average of these numbers. Use...

    1- Write a program to read 10 numbers and find the average of these numbers. Use a while loop to read these numbers and keep track of input numbers read. Terminate the while loop with a sentinel value. 2- Now modify the program to find the maximum of these numbers as well. The program should print the number of elements read as input and run until -1 is entered. (-1 is the sentinel that terminates the loop and the program)...

  • Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the...

    Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...

  • Create a java program which will prompt a user to input a product and its cost....

    Create a java program which will prompt a user to input a product and its cost. Using a while loop that will run until the sentinel value of “stop” (any case) is entered, the program will look for items with a cost greater than or equal to $100.00. The program will find the average cost of those items. Note: immediately after your statement containing input.nextDouble() you will need to add the following input.nextLine() statement. This will cause the input scanner...

  • Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a...

    Write a Java program that generates an array of Fibonacci numbers. Specifications: The program -Fills a one-dimensional array with the first 30 Fibonacci numbers using a calculation to generate the numbers. Note: The first two Fibonacci numbers 0 and 1 should be generated explicitly as in -long[] series = new long[limit]; //create first 2 series elements series[0] = 0; series[1] = 1; -But, it is not permissible to fill the array explicitly with the Fibonacci series’ after the first two...

  • JAVA turn this psuedo code into java code. USING NO LOOPS! ALL LOOPS MUST BE TURNED...

    JAVA turn this psuedo code into java code. USING NO LOOPS! ALL LOOPS MUST BE TURNED INTO RECURSIVE CALLS. English: 1. Prompt for and read a number between 1 and 5. Repeat this step until the input is 1..5. 2. Repeat the following multiple times according to the number read in step 1. a. Read in a list of integers ending with a 0. The 0 marks the end of the input and is not considered part of the list...

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