Java Learning (ii)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.