Toshkent axborot texnalogiyalari universiteti farg’ona filiali tt va kt fakulteti 652-20 guruh talabasi xudoyberdiyev xasanjonning java dasturlash fanidan kalkulator dedlayn ishi
Download 1.3 Mb.
|
Xudoyberdiyev Xasanjon Kalkulator
TOSHKENT AXBOROT TEXNALOGIYALARI UNIVERSITETI FARG’ONA FILIALI TT VA KT FAKULTETI 652-20 GURUH TALABASI XUDOYBERDIYEV XASANJONNING JAVA DASTURLASH FANIDAN KALKULATOR DEDLAYN ISHI Topshiriq: Java dasturlash tili orqali konverter va kalkulator dasturini ishlab chiqish. Dasturning kod qismi: 1. import java.util.Scanner; 2. 3. public class Calculator { 4. public static void main(String[] args) { 5. Scanner input = new Scanner(System.in); 6. 7. System.out.println("Kalkulyator dasturiga hush kelibsiz!"); 8. System.out.println("Iltimos, birinchi sonni kiriting: "); 9. double num1 = input.nextDouble(); 10. 11. System.out.println("Iltimos, ikkinchi sonni kiriting: "); 12. double num2 = input.nextDouble(); 13. 14. System.out.println("Iltimos, amalni tanlang (+, -, *, /): "); 15. char operator = input.next().charAt(0); 16. 17. double result; 18. 19. switch(operator) { 20. case '+': 21. result = num1 + num2; 22. break; 23. 24. case '-': 25. result = num1 - num2; 26. break; 27. 28. case '*': 29. result = num1 * num2; 30. break; 31. 32. case '/': 33. result = num1 / num2; 34. break; 35. 36. default: 37. System.out.println("Noto'g'ri amal tanlandi!"); 38. return; 39. } 40. 41. System.out.println(num1 + " " + operator + " " + num2 + " = " + result); 42. } 43. } 44. Dastur natijasi: 1. java -cp /tmp/TW1sP6fA8h Calculator 2. Kalkulyator dasturiga hush kelibsiz! 3. Iltimos, birinchi sonni kiriting: 4. 22 5. Iltimos, ikkinchi sonni kiriting: 33 6. Iltimos, amalni tanlang (+, -, *, /): 7. + 8. 22.0 + 33.0 = 55.0 9. Ushbu dasturda qo’shish, ayrish, bo’lish va ko’paytirish amallarini bajarish mumkin. 2. Java dasturlash tilida Asal maaxsulotining Kg va Litr o’lchov birliklarini konvertor dasturini yaratish. Dastur kod qismi: 1. import java.util.Scanner; 2. 3. public class Main { 4. public static void main(String[] args) { 5. Scanner scanner = new Scanner(System.in); 6. 7. System.out.print("Iltimos, o'lchov birlikni tanlang (kg yoki L): "); 8. String birlik = scanner.nextLine(); 9. 10. if (birlik.equals("kg")) { 11. System.out.print("Asal miqdorini kg da kiriting: "); 12. double asalKg = scanner.nextDouble(); 13. double asalL = asalKg / 1.38; 14. System.out.println("Asal miqdori " + asalL + " L ga teng."); 15. } else if (birlik.equals("L")) { 16. System.out.print("Asal miqdorini L da kiriting: "); 17. double asalL = scanner.nextDouble(); 18. double asalKg = asalL * 1.38; 19. System.out.println("Asal miqdori " + asalKg + " kg ga teng."); 20. } else { 21. System.out.println("Noto'g'ri birlik kiritildi!"); 22. } 23. } 24. } 25. Natija: 1. java -cp /tmp/TW1sP6fA8h Main 2. Iltimos, o'lchov birlikni tanlang (kg yoki L): kg 3. Asal miqdorini kg da kiriting: 2 4. Asal miqdori 1.4492753623188408 L ga teng. 5. Ushbu dasturda Asalning kilogramini litrga nisbati yoki aksincha holatini aniqlash mumkin. Malumot uchun: 1 Litr asal 1.38 kilogramga teng. Download 1.3 Mb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling