Q:

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

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

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

``````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();
}
}``````