76.5k views
1 vote
Write a question that prompts the user to input a sequence of numbers the algorithm should display the highest number entered. Data terminates when 000 is entered for. A number

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Java and asks the user to input a sequence of numbers separated by pressing the "ENTER" key and typing 000 to terminate the sequence. It saves all those numbers in an ArrayList and then goes through the Array to find and print the max number.

public static void MaxNumber () {

Scanner in = new Scanner(System.in);

System.out.println("Enter a as many numbers as you want seperated by the Enter Key... type 000 when done. ");

ArrayList<Integer> numbers = new ArrayList<>();

int exit = 1;

while (exit != 000) {

exit = in.nextInt();

numbers.add(exit);

}

int max = 0;

for (int x = 0; x < numbers.size(); x++) {

if (numbers.get(x) > max) {

max = numbers.get(x);

}

}

System.out.println(max);

}

User Frank Meulenaar
by
8.1k points