gogoWebsite

eg2: Define an integer array of length 10, loop into 10 integers, and then use loop to find the maximum and minimum values ​​in this array. (Array)

Updated to 7 hours ago
package Hcybx; import java.util.Scanner; // Define an integer array of length 10, loop into 10 integers, and then use loop to find the maximum and minimum values ​​in this array. public class Test { public static void main(String[] args) { int[] array = new int [10]; for (int i = 0; i < array.length;) { Scanner input = new Scanner(System.in); System.out.println("Please enter the first"+(i+1)+"Number of numbers:"); if (input.hasNextInt()) {//Judge whether the console gets an integer int num = input.nextInt(); array[i] = num; i++;//The number of int type was only +1 at that time }else { System.out.println("Please enter an integer!"); } } int max = array[0]; int min = array[0]; for (int i = 1; i < array.length; i++) { if (max<array[i]) { max=array[i]; } if (min>array[i]) { min=array[i]; } } System.out.println("The maximum value is:"+max+", the minimum value is:"+min); } }