Java Chapter III Selection structure

Source: Internet
Author: User

Chapter III Selection Structure

If basic syntax:

if (condition) {//Expression
code block
}

eg
int a = 10;
if (a > 1) {
System.out.println ("content");
}


if () {
code block
}else{
code block
}
eg
If (score >= 90) {
System.out.println ("Reward Mp4 One");
}else{
System.out.println ("shoot");
}

Syntax:
if (condition) {
//code block
}else if (condition) {
//code block
}eles if (condition) {
//code block
}..... {
//code block
}else{
//code block
}
eg:
if (score <=) {
System.out.println ("Pull out, shoot");
}else if (score <=) {
System.out.println ("Pull out, go to jail for 20 years");
}else if (score <=) {
System.out.println ("Find an Object");
}else{
System.out.println ("Let the object to throw!!!!" ");
}

Grammar:
if (condition) {
if (condition) {
.....
}else if (condition) {
.....
}else{
.......
}
}else{
.......
}

eg:
if (Miao <=) {
System.out.println ("Please enter gender (male, female, Transgender):");
//char gender = Input.next (). charAt (0);
String gender = Input.next ();
if (gender.equals ("male")) {
System.out.println ("Enter the men's finals");
}else if (gender.equals ("female")) {
System.out.println ("Enter the women's finals");
}else if (gender.equals ("transsexual")) {
System.out.println ("into the transsexual Finals");
}else{
System.out.println ("You are not Human");
}
}else{
System.out.println ("Obsolete!!! ");
}

Java Chapter III Selection structure

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.