I have the following code:
import java.util.Scanner;
public class WhileLoop {
public static void main(String[] args) {
int number;
int maxValue = Integer.MAX_VALUE;
int minValue = Integer.MIN_VALUE;
Scanner input = new Scanner (System.in);
System.out.println("Enter the length of numbers");
int loop = input.nextInt();
for(int i=1; i<=loop; i++){
System.out.println("Enter a number: ");
number = input.nextInt();
if (number > maxValue) {
maxValue = number;
}
if (number < minValue){
minValue = number;
}
}
System.out.println("Maximum Value is : " + maxValue);
System.out.println("Minimum Value is : " + minValue);
}
}
its showing the result:
Maximum Value is : 2147483647
Minimum Value is : -2147483648
Can any buddy help me out?