22
loading...
This website collects cookies to deliver better user experience
if (condition) {
//code to be executed
}
System.out.print("Age is greater than 18");
ကိုအလုပ်လုပ်ပါတယ်။if (condition) {
//code to be executed if condition is true
} else {
//code to be executed if condition is false
}
System.out.println("odd number");
ကို အလုပ် လုပ်သွားပါတယ်။if (condition1) {
//code to be executed if condition1 is true
} else if (condition2) {
//code to be executed if condition2 is true
} else if (condition3) {
//code to be executed if condition3 is true
}
//you can add else if as much as you can...
else {
//code to be executed if all the conditions are false
}
if (condition1) {
//code to be executed
if (condition2) {
//code to be executed
}
}
switch(expression){
case value1:
//code to be executed;
break; //optional
case value2:
//code to be executed;
break; //optional
//can add more cases.....
default:
//code to be executed if all cases are not matched;
}
System.out.println("10");
ဆိုတဲ့ operation ကိုအလုပ်လုပ်ပါလိမ့်မယ်။ ဒါပေမယ့် အခု number ရဲ့တန်ဖိုးက 20 ဖြစ်နေတဲ့အတွက် ဒုတိယ case မှာ မှန်သွားပါလိမ့်မယ်။ အဲ့တော့ program ကို run လိုက်တဲ့အခါမှာ 20 ဆိုပြီး output ထွက်ပါမယ်။ တစ်ခုသိထားရမှာက တကယ်လို့ ဒုတိယ case မှာသာ break statement မထည့်ထားဘူးဆိုရင်အောက်က တတိယ case အထိပါဆက်သွားမှာဖြစ်ပြီး 30 ကိုပါ output ထုတ်ပေးသွားမှာဖြစ်ပါတယ်။ အဲ့ဒါကြောင့် case တစ်ခုချင်းစီသာ အလုပ်လုပ်လိုပါက case ရဲ့အဆုံးရောက်တိုင်း break; ကိုမဖြစ်မနေထည့်ပေးဖို့ လိုအပ်ပါတယ်။