Question #47450

Find the biggest number from a sequence of input numbers from keyboard.
Hint: use of Scanner class to accept input and hasNextInt() function

Expert's answer

Answer on Question #47450, Engineering, Other

Problem.

Find the biggest number from a sequence of input numbers from keyboard.

Hint: use of Scanner class to accept input and hasNextInt() function

Solution.

Code


import java.util Scanner;
public class Main {
public static void main(String[] args) {
Scanner myScanner = new Scanner(System.in);
int i = 0;  // counter
int number;  // new number
int max = 0;  // max
while (myScanner.hasNextInt()) {
i++;
number = myScanner.nextInt();
if (i == 1) {
max = number;
} else if (number > max) {
max = number;
}
}
System.out.println("Max: " + Integer.toString(max));
}
}

Result

3 - 10 4 1 7 - 3 0 end

Max: 7

https://www.AssignmentExpert.com

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

LATEST TUTORIALS
APPROVED BY CLIENTS