Thuta Learning
ရှာဖွေရန်
BasicProgrammingbeginner

Variables

စိတ်လျှော့ပါ။ ဒီခန်းကို စာအုပ်လိုမဟုတ်ဘဲ စကားပြောသလိုပဲ၊ နားလည်လွယ်အောင် ရှင်းပါမယ်။

Variable ဆိုတာ data သိမ်းဖို့အသုံးပြုတဲ့ နာမည်ပေးထားသော storage လေးပါ။ Java က statically typed language ဖြစ်လို့ variable တစ်ခုကိုမသုံးခင် data type ကို ကြိုပြောရပါတယ်။ Java ကို “ဒီ box ထဲမှာ ဘာအမျိုးအစားထည့်မလဲ?” လို့ကြိုတင်ပြောပေးရတာပါ။

java
public class Main {
  public static void main(String[] args) {
    String name = "Aung";
    int age = 30;
    double height = 5.8;
    boolean isStudent = false;

    System.out.println("Name: " + name);
    System.out.println("Age: " + age);
    System.out.println("Height: " + height);
    System.out.println("Student: " + isStudent);
  }
}

String က စာသားသိမ်းပါတယ်။ int က ကိန်းပြည့်၊ double က ဒသမကိန်း၊ boolean က true/false တန်ဖိုးသိမ်းပါတယ်။ + operator ကို String နဲ့တွဲသုံးတဲ့အခါ text တွေကိုဆက်ပေးပါတယ်။

You should see
Name: Aung Age: 30 Height: 5.8 Student: false

လက်တွေ့အသုံးချမှု

User profile, product price, login status, score, inventory quantity စတဲ့ app data အားလုံးကို variable concept နဲ့ပဲစတင်ထိန်းချုပ်ပါတယ်။

ဒီနေရာမှာ လူအများမှားတတ်တယ်

  • int age = "30"; လို့ရေးရင် 30 ကို text အဖြစ်ထည့်ထားတာဖြစ်လို့ type mismatch error တက်နိုင်ပါတယ်။
Variables | Thuta Learning