Q:

Write a java program that will read a specific number of integers n and then print the maximum number

0

Write a java program that will read a specific number of integers n and then print the maximum number.

Name your class Maximum

Note: The two constants Integer.MIN_VALUE and Integer.MAX_VALUE represent the minimum and maximum integer in Java respectivly. You can use them in the finding the maximum or minimum algorithm.

Try printing them and see the number being printed. Is it higher or lower than you expected? Also try to print for Double and Short.

 

Sample run 1

Enter how many numbers you have? 7

Enter the numbers : 1 200 -1 3 0 23 14

The Maximum is 200

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

import java.util.Scanner;
public class Maximum {
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int x, n, max= Integer.MIN_VALUE;
System.out.print("Enter how many numbers you have: ");
n = kb.nextInt();
System.out.print("Enter the numbers: ");
for (int i=1; i<=n;i++) {
x = kb.nextInt();
if (x>max) max = x;
}
System.out.println("The maximum is: "+max);
kb.close();
}
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Write a Java program that will operate as sale cas... >>
<< Write a java program that will read a specific num...