Learn Java from zero (3)--Process Control

Source: Internet
Author: User

1. Java process structure: sequential structure, selection structure (branch structure), loop structure

2, select the structure: If statement, switch statement.

   

if (condition) {  ...    } Else {  ...  }
Switch (X) {   Case 1:          ...  Break ;     Case 2:                       //x==2 and x==3 when the same statement is executed    3:         ...           Break ;        default  :         ...           Break ;    }

3, get keyboard input content:

① Importing package: Import Java.util.Scanner; or java.util.*;

② Create Scanner object: Scanner sc=new Scanner (system.in);

③ get user input: int a=sc.nextint ();

Double b=sc.nextdouble ();

String S=sc.next (); or String s=sc.nextline ();

4. String comparison:

= = Compare addresses

Equals Method Comparison Value

Note: When using the Equals method, it is best to write the constants in front, such as

"Male". Equals (gender). If you use Gender.equals ("male"), if you gender=null, the program throws an exception. Tring S=sc.next (); or String s=sc.nextline ();

5. Connection of strings:

Connection symbol: +

Attention:

System.out.println (3.0+2+ "3.0");//output Result: 5.03.0

SYSTEM.OUT.PRINTLN ("3.0" +2+3.0);//output Result: 3.023.0

SYSTEM.OUT.PRINTLN ("3.0" +2*3.0);//output Result: 3.06.0

System.out.println (3.0-2+ "3.0");//output Result: 1.03.0

SYSTEM.OUT.PRINTLN ("3.0" +2.5-1.0);//Compilation error

Learn Java from zero (3)--Process Control

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.