Java conditions and looping statements
The first way to solve the sort task that the master gave me was to compare the number of each input, the maximum minimum value, and write the program by using only the condition and the loop statement:
Import java.util.*;
public class Homework2 {
public static void Main (string[] args) {
Scanner in = new Scanner (system.in);
int min = 0;
int max = 0;
System.out.print ("Please enter a number:");
int num = In.nextint ();
while (num! = 0) {
if (num > Max) {
max = num;
} else if (min > num) {
min = num;
}
System.out.print ("Please enter the number again, enter 0 to end:");
num = In.nextint ();
}
System.out.println ("max =" + max);
System.out.println ("min =" + min);
}
}
Import java.until.* represents all the unreferenced programs contained in the Java package until, including the data scanner function that is passed in from the keyboard;
• When the number entered is not zero, enter the loop, compare with the maximum minimum value saved and fix the value appropriately
• After entering multiple data, enter 0 to end and output the maximum minimum value
Learn more about function call names and learn about array traversal (macro definition?). )
Characters converted to integers have not begun to think
Java Learning (ii)