Branch statement (IF) Practice Java code

Source: Internet
Author: User


1  PackageXuexi;2 3 ImportJava.util.Scanner;4 5  Public classLianxi {6     7      Public Static voidMain (string[] args) {8 9System.out.println ("Please enter 1 numbers and return");TenScanner in =NewScanner (system.in); One     inti1=in.nextint (); ASystem.out.println ("Please enter 1 sets of numbers and return"); -     intI2=in.nextint (); -     inti3=i1+I2; theSystem.out.println ("Sum of 2 groups of numbers =" +i3); -      -              -      +     } -      +}
Enter 2 numbers and add sums

1  PackageXuexi;2 3 ImportJava.util.Scanner;4 5  Public classFenzhiyuju {6 7      Public Static voidMain (string[] args) {8 9Scanner in =NewScanner (system.in);Ten         intA = 1;//1. Short sleeves 2, long sleeves OneSYSTEM.OUT.PRINTLN ("Please select Type (1, short sleeve 2, long sleeves)"); AA =in.nextint (); -  -         if(A = = 1) { theSYSTEM.OUT.PRINTLN ("I want to buy short sleeves"); -SYSTEM.OUT.PRINTLN ("Please select color: (1, White, 2 for Black)"); -             intb =in.nextint (); -             if(b = = 1) { +System.out.println ("I chose white.")); -}Else { +System.out.println ("I chose black.")); A             } at         } -  -         Else { -System.out.println ("I chose long sleeves"); -SYSTEM.OUT.PRINTLN ("Please select color (1, yellow, 2, green)"); -             intc =in.nextint (); in             if(c = = 1) { -System.out.println ("I chose yellow"); to}Else { +System.out.println ("I chose green"); -             } the  *         } $System.out.println ("This is the dress you want, please.");Panax Notoginseng  -     } the}
buy clothes to choose

Import Java.util.Scanner; Reference

Scanner in = new Scanner (system.in);

A = In.nextint ();

Branch statement (IF) Practice Java code

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.