Javada kichik dastur — kalkulyator yaratish

java dasturlash tilini o'rganishni xohlovchilar uchun darsliklar


Shu vaqtgacha o’rganganlarimizdan  foydalanib kichik qo’shish amalini bajaradigan dastur tuzamiz. Bunga ko’ra foydalanuvchi ikkita son kiritadi va dastur ikkalasini qo’shib yig’indisini hisoblab beradi.

  1.   import java.util.Scanner;
  2.   public class Kalkulyator {
  3.   public static void main (String args[]){
  4.   Scanner o=new Scanner (System.in);
  5.    System.out.println («Birinchi sonni kirit»);
  6.    int son1=o.nextInt ();// birinchi sonni kiritish uchun
  7.   System.out.println («Ikinchi sonni kirit»);
  8.    int son2=o.nextInt (); // ikkinchi sonni kiritish uchun
  9.  
  10.   int natija=son1+son2;
  11.   System.out.println ("Yig'indi "+natija);
  12.   }

 

NATIJA:

Birinchi sonni kirit

10

Ikinchi sonni kirit

12

Yig'indi 22

 

IZOH: foydalanuvchi biron narsani kirita olishi uchun java util paketidan Scanner klasini import qilamiz (1-qator). Keyin undan foydalanish uchun obyektini yaratamiz (5-qator). “nextInt () metodi foydalanuvchidan int turidagi sonni olib “son1” o’zgaruvchisiga to’playdi (7-qator). Xuddi shunday ikkinchi kiritilgan son “son2” o’zgaruvchisida to’planadi (10-qator). int turidagi “natija” o’zgaruvchisiga “son1” va “son2” o’zgaruvchilarining qiymatlari yig’indisi  to’planadi (13-qator). O’shandan so’ng “natija” ning qiymati “son1” va “son2” ning qiymatiga teng. Bu natijani ekranda ko’rishimiz mumkin (14-qator).

Bu mavzu bo'yicha savol va fikr mulohazalaringizni kommentariyada qoldiring. Yangi ma'qolalar uchun obuna bo'lishni unutmang.

Mukammal darajada tushinish uchun videoni ko'rib chiqing:

Like this post? Please share to your friends:
Fikr bildirish

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: