Process Control
Compound statement: {}
Conditional statements
//one if(){ } else{ } //tow if(){} //three if(){ } else if(){ } // at Four Switch (expression) { Constant 1 case: { BREAK};
Case constant 2: {
} BREAK;
Case constants. 3: {
} BREAK;
default:
{}
[BREAK;]
......
}
loop statement:
while(){
}
do{
}while();
for()
{
}
Out of the loop: continue, break
By calculating a while loop 1 + 1/ 2! + 1/ 3! ... 1/ 20!
package first; public class a { public static void main(String[] args) { // TODO Auto-generated method stub float sum = 0; int i=1; long j; int k; while(i<=20) { j=1; for(k=1;k<=i;k++) { j*=k; } sum+=(1.0/j); i++; } System.out.println(sum); } }
Application if statement to determine whether a given year is a leap year
package first; import java.util.Scanner; public class a { public static void main(String[] args) { // TODO Auto-generated method stub float sum = 0; int year; Scanner cin=new Scanner(System.in); year=cin.nextInt(); if((year%100!=0&&year%4==0)||year%400==0) System.out.println ( "leap year" ); the else System.out.println ( "average year" ); } }