JAVA Overview (7) Branch control if switch (Code practice 2)

Source: Internet
Author: User

Public static void main (String [] args ){

Int inVual = 45;

If (inVual> 20 ){
System. out. println ("Young people ");
}
Else if (inVual> 40 ){
System. out. println ("middle-aged ");
}
Else if (inVual> 60 ){
System. out. println ("Elderly ");
}
Else {
System. out. println ("incorrect input, please input again ");
}


Int a = 9, B;
System. out. println ();
B = a> 1? 100: 200;
System. out. println (B );

If (a> 1 ){
B = 100;
System. out. println (B );
} Else {
B = 200;
System. out. println (B );
}

If (inVual> 60 ){
System. out. println ("Elderly ");
}
Else if (inVual> 40 ){
System. out. println ("middle-aged ");
}
Else if (inVual> 20 ){
System. out. println ("Young people ");
} Else {
System. out. println ("Wang chenglong is a pig ");
}


If (inVual> 15 & inVual <21 ){
System. out. println ("Young people ");
}
Else if (inVual> 21 & inVual <46 ){
System. out. println ("middle-aged ");
}
Else if (inVual> 46 & inVual <110 ){
System. out. println ("Elderly ");
}
Else {
System. out. println ("incorrect input. Please input another ···");
}

Char X = '2 ';
Switch (X ){
Case '1 ':
System. out. println ("1 ");
Break;
Case '2 ':{
System. out. println ('2 ');
}
Case '3 ':{
System. out. println ("3 ");
}
Case '4 ':{
System. out. println ("4 ");
Break;
}
Case '5 ':{
System. out. println ("5 ");
Break;
}

Default: System. out. println ("incorrect input, please input again ");
Break;
}

Int ssq = 0 + inVual ++ 100;
System. out. println (ssq );

Related Article

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.