Professional Documents
Culture Documents
5 Statements
5 Statements
Java SE
Contents
Operators
Expressions
Statements
Operators
Operator Type Operators Description
• eရ:သ#:ရ#တ,င.လ@ မ+်သiueရ:သ#:ရမ+်ဆiuသ+်ကiu
တiတiက"က" သတ.မ<တ.ထ#:ပ5သ+်
a+b/c
a + (b / c)
Statements
• အဓiပW5ယ.1ပX.Lစu0eသ# စ#eSက#င.$တစ.eSက#င.$အ#$ Statement ဟueခFဆiuသည.။
• Expression Statement
အခ"iueသ# Expression မ"#$၏eန#က.တ,င. “;” အ#$ eရ$သ#$လiuက.\u07<င.L Statement
တစ.ခu1ဖစ.လ#7iuင.BပC$၊၎င.$တiuအ#$ Expression Statement ဟu eခFဆiuပ5သည.။
• Declaration Statement
အသu0$1ပuလiuသX.L Variable မ"#$အ#$ Declare လuပ.သX.L Statement မ"#$အ#$
Declaration Statement ဟu eခFပ5သည.။
if for
if / else while
switch
if statement
true false
boolean expression
if (boolean expression) {
statements ;
Statement
}
other statements;
if / else statement
true
Boolean
false
if (boolean expression) {
expression
statements ;
Statement for true Statement for false
} else {
other statements;
}
if / else if / else
if (expression 1) {
true
Condition 1
false statement 1 ;
true false
} else if (expression2) {
Statement 1 Condition 2
statement 2;
Statement 2 Statement 3
} else {
statement 3;
}
switch
public void showGrade(char mark) { • တန.ဖiu$တစ.ခuအeပFလiuက.၍
switch(mark) { e1ပ#င.$လည.$လuပ.eဆ#င.
case A : eစလiuသX.L အခ5မ"iu$
System.out.println( Grade A );
break;
• case အတ,င.$eတ,L;iပ5က
case B :
break အ#$ မeတ,L မခ"င.$
System.out.println( Grade B );
break;
လuပ.eဆ#င.သ,#$မည.
default:
System.out.println( Other Grade ); • case အတ,င.$တ,င.
default; မeတ,L;iပ5က default အ#$
} လuပ.eဆ#င.မည.
}
switch Vs if / else if / else
• မည.သX.L အခ5မ"iu$တ,င. switch အ#$ အသu0$1ပuသင.L၍
မည.သX.L အခ5မ"iu$တ,င. if / else if / else အ#$ အသu0$1ပu
သင.Lသနည.$။
• တiက"eသ#တန.ဖiu$တစ.ခu အeပFမKတည.၍
လuပ.eဆ#င.မKLအ#$ခ,@1ခ#$လiuပ5က eရ$သ#$ပu0;င.$လင.$eသ#
switch အ#$ eရ$သ#$သင.L၍၊ အတiuင.$အတ# ပမ#ဏ
အeပFမKတည.၍ ခ,@1ခ#$အသu0$1ပuလiuပ5က if / else if / else
အ#$ အသu0$1ပuသင.Lပ5သည.။
Looping Statement
• လuပ.eဆ#င.ခ"က.မ"#$အ#$ အ_ကiမ._ကiမ.1ပuလuပ.လiuသX.L
အခ5အသu0$1ပuရပ5သည.။
Initialization Update
int i = 0 i ++
do {
String selectedOption =
displayMenuToUser();
if(selectedOption.equals( exit ) {
exitSelected = true;
}
while(bunsAvailable) {
// prepare burger
if(nomoreBurns) {
bunsAvailable = false;
}
}
do while & while
branching
return
break
continue
return statement
public boolean isEven(int val) { • Return Type သည. void
return (val%2) == 0; မဟuတ.eသ# method မ"#$တ,င.
} return type ၏
တန.ဖiu$အမ"iu$အစ#$ အတiuင.$
public void writeData(String [] array) { တန.ဖiu$တစ.ခuအ#$
if(null == array ¦¦ array.length == 0) { eန#က.ဆu0$တ,င. မ1ဖစ.မeန
return; return လuပ.ရပ5သည.။
}
• Method တစ.ခuအ#$
for(String s : array) { အဆu0$သတ.လiuပ5က return
System.out.println(s);
statement အ#$
}
အသu0$1ပu7iuင.ပ5သည.။
}
break statement
int i = 1;
if (i % 3 == 0) {
break;
}
i++;
}
• While သiuမဟuတ. For looping block အတ,င.$ break statement အ#$ eတ,L;iပ5က
လက.;ieနရ#တ,င. loop အ#$ ရပ.တ7.LBပC$ eန#က.ပiuင.$;i statement မ"#$အ#$
ဆက.လuပ.မည. မဟuတ.eတ#Lပ5။
continue statement
public static void main(String[] args) {
String str ="Java is amazing programming language!";
• code block
• expressions
• Assignments
• return statements
• try blocks
• throw statements
break with label
public static void main(String[] args) {
outer:
for (int i = 0; i < 3; i++) {
System.out.println("Outer Counter : " + i);
for (int j = 0; j < 5; j++) {
if((j + 1)%3 == 0)
break outer;
System.out.println("Inner Counter : " + j);
}
}
}
search:
for (int i = 0; i < array.length; i++) {
int j = 0;
while (array[i].length() > j) {
if(array[i].charAt(j ++) == 'a') {
continue search;
}
}
System.out.println("\"" + array[i] + "\" does not contain char a.");
}