Selection (if/else) (condition ပေါ်မူတည်ပြီး လမ်းကြောင်း ရွေးခြင်း)
B2.3.2 - Construct programs utilizing appropriate selection structures.
မြန်မာလို: သင့်တော်တဲ့ selection structure (condition ပေါ်မူတည်ပြီး လမ်းကြောင်း ရွေးပေးတဲ့ code ပုံစံ) တွေကို သုံးပြီး program တွေကို ကိုယ်တိုင် တည်ဆောက်နိုင်ရပါမယ်။
အဓိက အယူအဆများ
Selection (condition ပေါ်မူတည်ပြီး လမ်းကြောင်း ရွေးခြင်း) က program ကို ဆုံးဖြတ်ချက် ချနိုင်စေပါတယ်။ Condition (မှန်လား မှားလား စစ်တဲ့ အခြေအနေ) တစ်ခု true (မှန်) လား false (မှား) လား ဆိုတာပေါ် မူတည်ပြီး program က မတူတဲ့ လမ်းကြောင်းတွေကို သွားပါတယ်။
| ပုံစံ | ဘယ်အချိန် သုံးမလဲ |
|---|---|
if | Condition true ဖြစ်တဲ့အခါ လုပ်ဆောင်ချက် တစ်ခု လုပ်တယ် |
if-else | မတူတဲ့ လမ်းကြောင်း နှစ်ခု: true အတွက် တစ်ခု၊ false အတွက် တစ်ခု |
if-else if-else | Condition အများကို အစဉ်လိုက် စစ်တယ် |
Nested if (if ထဲမှာ ထပ်ပါတဲ့ if) | ဆုံးဖြတ်ချက် တစ်ခုထဲမှာ နောက်ထပ် ဆုံးဖြတ်ချက် တစ်ခု ပါတယ် |
Relational Operators (တန်ဖိုး နှစ်ခုကို နှိုင်းယှဉ်တဲ့ operator များ)
| Operator | အဓိပ္ပာယ် | ဥပမာ |
|---|---|---|
== | ညီတယ် | score == 100 |
!= | မညီဘူး | input != 0 |
< | ငယ်တယ် | age < 18 |
> | ကြီးတယ် | temp > 30 |
<= | ငယ်တယ် ဒါမှမဟုတ် ညီတယ် | marks <= 50 |
>= | ကြီးတယ် ဒါမှမဟုတ် ညီတယ် | grade >= 90 |
Boolean (Logical) Operators (condition တွေကို ပေါင်းစပ်ပေးတဲ့ operator များ)
| Operator | အဓိပ္ပာယ် | ဥပမာ |
|---|---|---|
&& | AND: နှစ်ခုလုံး true ဖြစ်ရမယ် | age >= 13 && age <= 17 |
\|\| | OR: အနည်းဆုံး တစ်ခု true ဖြစ်ရမယ် | score < 0 \|\| score > 100 |
! | NOT: boolean (true ဒါမှမဟုတ် false တန်ဖိုးပဲ ယူတဲ့) တန်ဖိုးကို ပြောင်းပြန် လှန်တယ် | !isValid |
Primitive (Java ရဲ့ အခြေခံ ဒေတာ အမျိုးအစား) တန်ဖိုးတွေ (
int,boolean,char) ကို နှိုင်းယှဉ်ဖို့==ကို သုံးပါ။ String (စာသား) တွေကို နှိုင်းယှဉ်ဖို့ကတော့.equals()ကို အမြဲ သုံးပါ:if (name.equals("Alice")) { ... } // correct if (name == "Alice") { ... } // WRONG - compares memory addressesPython အတွက် မှတ်ချက်: ဒီထောင်ချောက်က Java မှာပဲ ရှိပါတယ်။ Python မှာ
==က string ရဲ့ အကြောင်းအရာ (စာလုံးတွေ) ကို နှိုင်းယှဉ်လို့if name == "Alice":က မှန်ပါတယ်။ Python မှာ boolean operator တွေကိုလည်း&&,||,!အစားand,or,notဆိုတဲ့ စကားလုံးတွေနဲ့ ရေးပါတယ်။
အဆင့်ဆင့် ရှင်းပြထားတဲ့ ဥပမာများ
ဥပမာ 1: ရိုးရိုး if-else၊ အောင်လား ကျလား
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.print("Enter your score: ");
int score = input.nextInt();
if (score >= 50) {
System.out.println("Pass");
} else {
System.out.println("Fail");
}
score = int(input("Enter your score: "))
if score >= 50:
print("Pass")
else:
print("Fail")
အလုပ်လုပ်ပုံ:
- Score (အမှတ်) က 50 ဒါမှမဟုတ် 50 ထက် ပိုရင်
"Pass"(အောင်) ကို print ထုတ်ပါတယ်။ - မဟုတ်ရင် (score က 50 အောက် ဆိုရင်)
"Fail"(ကျ) ကို print ထုတ်ပါတယ်။ - Branch (condition အရ run မယ့် code လမ်းကြောင်း) တစ်ခုတည်း ပဲ run ပါတယ်။ Branch နှစ်ခုက mutually exclusive (တစ်ခု run ရင် နောက်တစ်ခု မ run တဲ့) ဖြစ်ပါတယ်။
ဥပမာ 2: if-else if-else၊ grade ခွဲတဲ့ အမှတ် နယ်နိမိတ်များ
စစ်ရမယ့် အမှတ် အပိုင်းအခြားတွေ အများကြီး ရှိတဲ့အခါ if-else if-else chain (condition တွေကို တစ်ခုပြီး တစ်ခု ဆက်ထားတဲ့ ပုံစံ) ကို သုံးပါ။ Java က condition တွေကို အပေါ်ကနေ အောက်ကို စစ်ပြီး ပထမဆုံး true ဖြစ်တဲ့ branch ကို ယူပါတယ်။
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.print("Enter your test score: ");
int score = input.nextInt();
if (score >= 90) {
System.out.println("Grade: 7");
} else if (score >= 80) {
System.out.println("Grade: 6");
} else if (score >= 70) {
System.out.println("Grade: 5");
} else if (score >= 60) {
System.out.println("Grade: 4");
} else if (score >= 40) {
System.out.println("Grade: 3");
} else {
System.out.println("Below passing");
}
score = int(input("Enter your test score: "))
if score >= 90:
print("Grade: 7")
elif score >= 80:
print("Grade: 6")
elif score >= 70:
print("Grade: 5")
elif score >= 60:
print("Grade: 4")
elif score >= 40:
print("Grade: 3")
else:
print("Below passing")
Condition တွေကို အပေါ်ကနေ အောက်ကို စစ်တာကြောင့် score 85 ဆိုရင်
score >= 90ကို အရင် ရောက်ပါတယ် (false)။ ပြီးမှscore >= 80ကို ရောက်ပါတယ် (true)၊ အဲဒီ branch ကို ယူပါတယ်။ ကျန်တဲ့ condition တွေကို ဆက်မစစ်တော့ပါဘူး။
ဥပမာ 3: Nested if၊ အငယ်ဆုံး ကိန်းကို ရှာခြင်း
if တစ်ခုထဲမှာ နောက်ထပ် if တစ်ခု ထည့်ရေးရင် nested decision (ဆုံးဖြတ်ချက်ထဲမှာ ထပ်ပါတဲ့ ဆုံးဖြတ်ချက်) ဖြစ်ပါတယ်။
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.print("Enter three numbers: ");
int a = input.nextInt();
int b = input.nextInt();
int c = input.nextInt();
if (a < b) {
if (a < c) {
System.out.println(a + " is the smallest.");
} else {
System.out.println(c + " is the smallest.");
}
} else {
if (b < c) {
System.out.println(b + " is the smallest.");
} else {
System.out.println(c + " is the smallest.");
}
}
# split() breaks one input line into pieces - IB's named tool for this
values = input("Enter three numbers: ").split()
a = int(values[0])
b = int(values[1])
c = int(values[2])
if a < b:
if a < c:
print(a, "is the smallest.")
else:
print(c, "is the smallest.")
else:
if b < c:
print(b, "is the smallest.")
else:
print(c, "is the smallest.")
အလုပ်လုပ်ပုံ:
- ပထမဆုံး
aနဲ့bကို နှိုင်းယှဉ်ပြီး ဖြစ်နိုင်တဲ့ ကိန်း နှစ်ခုအထိ ကျဉ်းလိုက်ပါတယ်။ - ပြီးရင် ကျန်နေတဲ့ ကိန်းကို
cနဲ့ နှိုင်းယှဉ်ပါတယ်။ - Nested
ifတစ်ခုချင်းက branch ထဲမှာ နောက်ထပ် ဆုံးဖြတ်ချက် တစ်ခု ချပါတယ်။
ဥပမာ 4: Boolean operator များ၊ range check (တန်ဖိုးက သတ်မှတ်ထားတဲ့ အပိုင်းအခြားထဲမှာ ရှိမရှိ စစ်ခြင်း)
ရှုပ်ထွေးတဲ့ ဆုံးဖြတ်ချက်တွေအတွက် condition တွေကို && (AND) နဲ့ || (OR) သုံးပြီး ပေါင်းစပ်ပါ။
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.print("Enter your age: ");
int age = input.nextInt();
if (age >= 13 && age <= 17) {
System.out.println("You are a teenager.");
} else if (age >= 18) {
System.out.println("You are an adult.");
} else {
System.out.println("You are a child.");
}
age = int(input("Enter your age: "))
if age >= 13 and age <= 17:
print("You are a teenager.")
elif age >= 18:
print("You are an adult.")
else:
print("You are a child.")
// Validation: reject out-of-range scores
System.out.print("Enter score (0-100): ");
int score = input.nextInt();
if (score < 0 || score > 100) {
System.out.println("Invalid score!");
} else {
System.out.println("Score recorded: " + score);
}
# Validation: reject out-of-range scores
score = int(input("Enter score (0-100): "))
if score < 0 or score > 100:
print("Invalid score!")
else:
print("Score recorded:", score)
အဖြစ်များတဲ့ အမှား:
if (age >= 13 && <= 17)လို့ ရေးမိတာပါ။ Java မှာ&&ရဲ့ ဘယ်ဘက်ရော ညာဘက်မှာပါ condition အပြည့်အစုံ ရေးရပါတယ်:age >= 13 && age <= 17။
ဥပမာ 5: Leap year (ရက်ထပ်နှစ်)၊ compound logic (condition အများကို ပေါင်းထားတဲ့ logic)
4 နဲ့ စားလို့ ပြတ်တဲ့ နှစ်က leap year ဖြစ်ပါတယ်။ ဒါပေမယ့် ရာစုနှစ် (100 နဲ့ စားလို့ ပြတ်တဲ့ နှစ်) တွေကတော့ 400 နဲ့ပါ စားလို့ ပြတ်မှ leap year ဖြစ်ပါတယ်။
import java.util.Scanner;
Scanner input = new Scanner(System.in);
System.out.print("Enter a year: ");
int year = input.nextInt();
if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)) {
System.out.println(year + " is a leap year.");
} else {
System.out.println(year + " is not a leap year.");
}
year = int(input("Enter a year: "))
if (year % 4 == 0 and year % 100 != 0) or (year % 400 == 0):
print(year, "is a leap year.")
else:
print(year, "is not a leap year.")
စမ်းသပ်ချက်များ:
- 2024 →
2024 % 4 == 0ဖြစ်ပြီး2024 % 100 != 0ဖြစ်လို့ → leap year ဖြစ်ပါတယ် - 1900 →
1900 % 4 == 0ဖြစ်ပေမယ့်1900 % 100 == 0ဖြစ်ပြီး1900 % 400 != 0ဖြစ်လို့ → leap year မဟုတ်ပါဘူး - 2000 →
2000 % 400 == 0ဖြစ်လို့ → leap year ဖြစ်ပါတယ်
Quick Check (အမြန် စစ်ဆေးမေးခွန်း)
Q1. score = 85 ဆိုရင် ဘာကို print ထုတ်မလဲ။
if (score >= 90) {
System.out.println("Grade: A");
} else if (score >= 80) {
System.out.println("Grade: B");
} else if (score >= 70) {
System.out.println("Grade: C");
}if score >= 90:
print("Grade: A")
elif score >= 80:
print("Grade: B")
elif score >= 70:
print("Grade: C") Q2. x = 15 ဆိုရင် ဘာကို print ထုတ်မလဲ။
if (x >= 10 && x <= 12) {
System.out.println("In range");
} else {
System.out.println("Out of range");
}if x >= 10 and x <= 12:
print("In range")
else:
print("Out of range") Q3. ဘာကို print ထုတ်မလဲ။
boolean isRaining = true;
if (!isRaining) {
System.out.println("Go outside");
} else {
System.out.println("Stay inside");
}is_raining = True
if not is_raining:
print("Go outside")
else:
print("Stay inside") Q4. Java မှာ String နှစ်ခုကို နှိုင်းယှဉ်တဲ့ မှန်ကန်တဲ့ နည်းက ဘာလဲ။
Q5. age = 150 ဆိုရင် age < 0 || age > 120 ရဲ့ ရလဒ်က ဘာလဲ။
Trace Exercise (code ကို တစ်ဆင့်ချင်း လိုက်ကြည့်ခြင်း)
ဒီ code ကို trace လုပ်ပါ: ပေးထားတဲ့ input (program ထဲ ထည့်ပေးတဲ့ ဒေတာ) အတွက် variable (တန်ဖိုး သိမ်းထားတဲ့ နာမည်ပေးထားတဲ့ နေရာ) တစ်ခုချင်းရဲ့ တန်ဖိုးနဲ့ print ထုတ်မယ့် စာကို ဖြည့်ပါ။
Input: score = 72, bonus = true
int score = 72;
boolean bonus = true;
String result;
if (score >= 80) {
result = "Distinction";
} else if (score >= 60) {
if (bonus) {
result = "Merit (with bonus)";
} else {
result = "Merit";
}
} else {
result = "Pass";
}
System.out.println(result);
score = 72
bonus = True
result = ""
if score >= 80:
result = "Distinction"
elif score >= 60:
if bonus == True:
result = "Merit (with bonus)"
else:
result = "Merit"
else:
result = "Pass"
print(result)
ရလဒ် ကော်လံမှာ true (မှန်) ဒါမှမဟုတ် false (မှား) ကို English လို ရိုက်ထည့်ပါ။ Print ထုတ်မယ့် စာကိုလည်း program ထုတ်ပေးတဲ့ အတိုင်း English လို ရိုက်ပါ။
| စစ်တဲ့ နေရာ | Condition | ရလဒ် |
|---|---|---|
| ပထမ if | score >= 80 → 72 >= 80 | |
| ပထမ else if | score >= 60 → 72 >= 60 | |
| Nested if | bonus |
ဘာကို print ထုတ်မလဲ။
Code Completion (code ကွက်လပ် ဖြည့်ခြင်း)
Temperature (အပူချိန်) ကို if-else if-else chain နဲ့ အမျိုးအစား ခွဲပေးတဲ့ ဒီ program ရဲ့ ကွက်လပ်တွေကို ဖြည့်ပါ: 30 နဲ့ အထက်ဆိုရင် “Hot” (ပူ)၊ 15 ကနေ 29 အထိဆိုရင် “Warm” (နွေး)၊ အဲဒီထက် နိမ့်ရင် “Cold” (အေး) ပါ။ ဒီလေ့ကျင့်ခန်းမှာ boundary value (အပိုင်းအခြား တစ်ခုရဲ့ အစွန်းမှာ ရှိတဲ့ တန်ဖိုး) တွေက ဘယ် branch ကို run မလဲ ဆုံးဖြတ်ပုံကို လေ့ကျင့်ရပါတယ်။
int temp = 35;
if (temp >= ) {
System.out.println("Hot");
} (temp >= 15) {
System.out.println("Warm");
} else {
System.out.println();
} ကိန်းတစ်ခုက 1 နဲ့ 100 ကြားမှာ (1 နဲ့ 100 ပါ အပါအဝင်) ရှိမရှိ စစ်တဲ့ condition ကို ဖြည့်ပါ။ ဒီလေ့ကျင့်ခန်းမှာ && (AND) operator နဲ့ relational operator သုံးတဲ့ နှိုင်းယှဉ်ချက် နှစ်ခုကို ပေါင်းပြီး range check တစ်ခု တည်ဆောက်ရပါတယ်။
int num = 50;
if (num && num ) {
System.out.println("Valid");
} else {
System.out.println("Invalid");
} Spot the Error (အမှား ရှာခြင်း)
ဒီ code က integer (ကိန်းပြည့်) နှစ်ခု တူရင် “Equal” (တူတယ်) လို့ print ထုတ်ရမှာပါ။ ဒါပေမယ့် comparison operator (တန်ဖိုး နှစ်ခုကို နှိုင်းယှဉ်တဲ့ operator) == အစား assignment operator (variable ထဲကို တန်ဖိုး ထည့်တဲ့ operator) = ကို သုံးထားပါတယ်။ အမှားပါတဲ့ line ကို ရွေးပါ၊ ပြီးရင် ပြင်နည်းကို ရွေးပါ။
int a = 5;
int b = 5;
if (a = b) {
System.out.println("Equal");
}ဘာမှားနေလဲ၊ ဘယ်လို ပြင်မလဲ။
ဒီ code က String variable ထဲမှာ "yes" ရှိရင် “Match” (ကိုက်တယ်) လို့ print ထုတ်ရမှာပါ။ ဒါပေမယ့် String တွေကို နှိုင်းယှဉ်ဖို့ == ကို မှားသုံးထားပါတယ်။ ဒါက Java မှာ အဖြစ်အများဆုံး အမှားတွေထဲက တစ်ခုပါ: String တွေကို == နဲ့ မဟုတ်ဘဲ .equals() နဲ့ နှိုင်းယှဉ်ရပါတယ်။ (ဒီမှာလို file တစ်ခုတည်းထဲမှာ literal (code ထဲမှာ တိုက်ရိုက် ရေးထားတဲ့ တန်ဖိုး) နှစ်ခု ရှိရင်တော့ Java က တူညီတဲ့ literal တွေကို ပြန်သုံးလို့ တိုက်ဆိုင်ပြီး Match လို့ ထွက်လာပါတယ်။ User ရိုက်ထည့်တဲ့ စကားလုံးဆိုရင်တော့ No match လို့ ထွက်ပါတယ်။ ဘယ်လိုပဲ ဖြစ်ဖြစ် == က မှားတဲ့ စစ်နည်းပါ။) Bug (code ထဲက အမှား) ကို ရှာပါ။
String answer = "yes";
if (answer == "yes") {
System.out.println("Match");
} else {
System.out.println("No match");
}ဘာမှားနေလဲ၊ ဘယ်လို ပြင်မလဲ။
Predict the Output (output ကို ကြိုခန့်မှန်းခြင်း)
ဒီ code က ဘာကို print ထုတ်မလဲ။ ဒီ code က else-if chain ကို ဘယ်အစဉ်နဲ့ စစ်လဲဆိုတာ နားလည်မလည် စစ်ပေးပါတယ်: Java က condition တွေကို အပေါ်ကနေ အောက်ကို စစ်ပြီး ပထမဆုံး true ဖြစ်တဲ့ branch ကိုပဲ run တယ်ဆိုတာ သတိရပါ။ Output (program က ထုတ်ပြတဲ့ ရလဒ်) ကို အတိအကျ ရိုက်ထည့်ပါ။
int x = 7;
if (x > 10) {
System.out.println("Big");
} else if (x > 5) {
System.out.println("Medium");
} else {
System.out.println("Small");
}
x = 7
if x > 10:
print("Big")
elif x > 5:
print("Medium")
else:
print("Small")
Mediumဒီ code က ဘာကို print ထုတ်မလဲ။ If-else block ရဲ့ နောက်က statement (code ညွှန်ကြားချက် တစ်ခု) တွေက ဘယ် branch ကို ယူခဲ့ယူခဲ့ အမြဲ run တယ်ဆိုတာကို ဒီ code က ပြပါတယ်။ Condition ပေါ် မူတည်ပြီး ထွက်တဲ့ output နဲ့ condition မပါဘဲ အမြဲ ထွက်တဲ့ output နှစ်ခုလုံးကို သတိထားကြည့်ပါ။
int a = 3;
int b = 5;
if (a > b) {
System.out.println(a);
} else {
System.out.println(b);
}
System.out.println("Done");
a = 3
b = 5
if a > b:
print(a)
else:
print(b)
print("Done")
5
DonePractice Exercises (လေ့ကျင့်ခန်းများ)
Core (အခြေခံ အဆင့်)
-
မကိန်းလား စုံကိန်းလား။ Integer တစ်ခုကို ဖတ်ပြီး အဲဒီကိန်းက မကိန်း (odd) လား စုံကိန်း (even) လား print ထုတ်ပေးတဲ့ program ကို ရေးပါ။
-
သုံးခုထဲက အကြီးဆုံး။ User ဆီကနေ integer သုံးခု ဖတ်ပြီး if-else if-else ကို သုံးကာ အကြီးဆုံး ကိန်းကို print ထုတ်ပါ။
-
Grade သတ်မှတ်ခြင်း။ Test score (0-100) တစ်ခုကို ဖတ်ပြီး grade boundary (grade တစ်ခုစီရဲ့ အမှတ် နယ်နိမိတ်) တွေကို သုံးကာ သက်ဆိုင်တဲ့ IB grade (7, 6, 5, 4, 3, 2, 1) ကို print ထုတ်ပါ။ (IB မှာ grade ကို 1 ကနေ 7 အထိ ပေးပြီး 7 က အမြင့်ဆုံးပါ။)
-
အပေါင်းကိန်း၊ အနုတ်ကိန်း ဒါမှမဟုတ် သုည။ ကိန်းတစ်ခုကို ဖတ်ပြီး အဲဒါက အပေါင်းကိန်း (positive) လား၊ အနုတ်ကိန်း (negative) လား၊ သုည (zero) လား print ထုတ်ပါ။
Extension (တိုးချဲ့ အဆင့်)
- လက်မှတ် ဈေးနှုန်း။ ရုပ်ရှင်ရုံ တစ်ရုံက ဒီလို ဈေးယူပါတယ်:
- 5 နှစ်အောက်: အခမဲ့
- 5-12: $8
- 13-64: $15
- 65+: $10
Customer ရဲ့ အသက်ကို ဖတ်ပြီး လက်မှတ် ဈေးနှုန်းကို print ထုတ်ပါ။ အသက်က အနုတ်ကိန်း မဖြစ်ရကြောင်း validate (မှန်မမှန် စစ်) လုပ်ပါ။
-
Quadrant ရှာခြင်း။ (x, y) coordinate (ကိုဩဒိနိတ်) အတွဲ တစ်ခုကို ဖတ်ပြီး အဲဒီ အမှတ်က ဘယ် quadrant (x ဝင်ရိုးနဲ့ y ဝင်ရိုးက ခွဲထားတဲ့ အပိုင်း လေးပိုင်းထဲက တစ်ပိုင်း) ထဲမှာ ရှိလဲ (I, II, III ဒါမှမဟုတ် IV) print ထုတ်ပါ။ ဝင်ရိုး တစ်ခုခုပေါ်မှာ ရှိနေရင်လည်း အဲဒါကို print ထုတ်ပါ။
- ရက်သတ္တပတ်ရဲ့ နေ့။ 1-7 ကြား ကိန်းတစ်ခုကို ဖတ်ပြီး သက်ဆိုင်တဲ့ နေ့ရဲ့ နာမည်ကို print ထုတ်ပါ။ တခြား ကိန်းဆိုရင် “Invalid” (မမှန်ကန်ဘူး) လို့ print ထုတ်ပါ။
Challenge (စိန်ခေါ်မှု အဆင့်)
-
တြိဂံ အမျိုးအစား ခွဲခြင်း။ အနား သုံးနားရဲ့ အလျားကို ဖတ်ပြီး အဲဒီ အနားတွေနဲ့ တြိဂံ ဖြစ်နိုင်မနိုင် ဆုံးဖြတ်ပါ။ ဖြစ်နိုင်ရင် equilateral (အနားညီ တြိဂံ)၊ isosceles (နှစ်နားညီ တြိဂံ) ဒါမှမဟုတ် scalene (အနားမညီ တြိဂံ) ဆိုပြီး အမျိုးအစား ခွဲပါ။
-
Leap year စစ်ခြင်း။ User ဆီကနေ နှစ် တစ်ခုကို ဖတ်ပြီး leap year ဟုတ်မဟုတ် ဆုံးဖြတ်ပါ။ 4 နဲ့ စားလို့ ပြတ်တဲ့ နှစ်က leap year ဖြစ်ပါတယ်၊ ဒါပေမယ့် ရာစုနှစ်တွေကတော့ 400 နဲ့ပါ စားလို့ ပြတ်ရပါမယ်။ ရလဒ်ကို ရှင်းပြချက်နဲ့ အတူ print ထုတ်ပါ။
GitHub Classroom (အလိုအလျောက် စစ်ဆေးတဲ့ test တွေပါတဲ့ programming assignment များ)
A class assignment on GitHub Classroom: use it when your teacher has set it. It needs a free GitHub account.
Working in the Codespace
- Accept and open. Accept the assignment above, open the link in the email from GitHub, then press Open in Codespace. In Java, change the status bar from Lightweight to Standard mode.
- Write and check. Open
src/Selection.javaand complete eachTODO. Press Run and compare the output with the comments, or runbash run-tests.shin the Terminal. - Submit. In Source Control, write a message, press Commit, then Sync Changes. Your teacher’s feedback arrives as a pull request called Feedback.
ဆက်စပ် ခေါင်းစဉ်များ
အရင် လေ့လာထားရမယ့် ခေါင်းစဉ်များ:
- Variables & Data Types (variable နဲ့ data type များ): variable တွေကို ကြေညာပုံနဲ့ data type (ဒေတာ အမျိုးအစား) တွေကို နားလည်ခြင်း
ဆက်စပ် ခေါင်းစဉ်:
- Iteration (Loops) (ထပ်ခါထပ်ခါ လုပ်ခြင်း): loop (ထပ်ခါထပ်ခါ run တဲ့ code အပိုင်း) ရဲ့ header (ပထမ line) မှာ condition တွေကို သုံးပါတယ်
နောက်ထပ် လေ့လာမယ့် ခေါင်းစဉ်များ:
- Iteration: နောက်ထပ် လေ့လာရမယ့် construct (program တည်ဆောက်တဲ့ အခြေခံ ပုံစံ) ပါ
- Loop တွေမှာ ဒီမှာ သင်ခဲ့တဲ့ boolean condition တွေကိုပဲ သုံးပါတယ်
Selection နဲ့ iteration ကို တွဲသုံးရင် ဘယ်လို ဆုံးဖြတ်ချက်မျိုးမဆို ချနိုင်ပြီး ဘယ်လို လုပ်ဆောင်ချက်မျိုးမဆို ထပ်ခါထပ်ခါ လုပ်နိုင်ပါတယ်။ Sequence (ရေးထားတဲ့ အစဉ်အတိုင်း တစ်ကြောင်းပြီး တစ်ကြောင်း run ခြင်း) နဲ့ ပေါင်းလိုက်ရင် ဒီ construct သုံးမျိုးနဲ့ ဘယ် algorithm (အယ်လ်ဂိုရီသမ်၊ ပြဿနာကို အဆင့်ဆင့် ဖြေရှင်းတဲ့ နည်းလမ်း) ကိုမဆို ဖော်ပြနိုင်ပါတယ်။