Examples of Java branch statements

Source: Internet
Author: User

1. Is the input year judged as a leap or common year?

System.out.println ("please Enter the year:");        Scanner sc=new  Scanner (system.in);        String ss=Sc.nextline ();         int year=integer.parseint (ss);         if (year%400==0 | | (year%4==0 && year%100!=0)) {            System.out.println (year + "years are leap");        } Else {            System.out.println (year + "years is common year");        }

2. Enter the height and weight sex to determine whether the body proportion is normal?

Scanner sex=NewScanner (system.in); System.out.println ("please Enter the gender:"); String SE=Sex.nextline (); if(se.equals ("male") {System.out.println ("please Enter your height:"); String He=Sex.nextline (); intsg=Integer.parseint (he); System.out.println ("please Enter your weight:"); String We=Sex.nextline (); inttz=Integer.parseint (we); intBZ = sg-100; if(bz-tz>=-3 && bz-tz<=3) {System.out.println (Normal); }Else{System.out.println ("not normal"); }                    }Else if(se.equals ("female") {System.out.println ("please Enter your height:"); String He=Sex.nextline (); intsg=Integer.parseint (he); System.out.println ("please Enter your weight:"); String We=Sex.nextline (); inttz=Integer.parseint (we); intBZ = sg-110; if(bz-tz>=-2 && bz-tz<=2) {System.out.println (Normal); }Else{System.out.println ("not normal"); }                    }Else{System.out.println ("you Go away!" "); }

3. Enter three number, output maximum value

System.out.println ("its Input Three number:"); Scanner v=NewScanner (system.in); String a=V.nextline (); inta1=Integer.parseint (a); String b=V.nextline (); intb1=Integer.parseint (b); String C=V.nextline (); intc1=Integer.parseint (c); intbig; if(a1>B1) {big=a1; if(a1>C1) {big=a1;            System.out.println (big); }Else{big=c1;            System.out.println (big); }        }Else{big=b1; if(b1>C1) {big=b1;            System.out.println (big); }Else{big=c1;            System.out.println (big); }        }

4. Login Verification

Scanner scan=NewScanner (system.in); System.out.println ("please Enter User name:"); String YHM=Scan.nextline (); System.out.println ("please Enter your password:"); String mm=Scan.nextline (); if(yhm.equals ("admin")){                        if(mm.equals ("admin") {System.out.println ("congratulations on your successful landing"); }Else{System.out.println ("sorry you entered the wrong password"); }                    }Else{System.out.println ("sorry you entered the wrong user name"); if(mm.equals ("admin")){                                                            }Else{System.out.println ("sorry you entered the wrong password"); }        }

Examples of Java branch statements

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.