1 va 100 sonlari orasidan tasodifiy sonlarni chiqaruvchi dastur tuzing
Download 17.96 Kb.
|
Jumayev Asilbek MI-303
1 va 100 sonlari orasidan tasodifiy sonlarni chiqaruvchi dastur tuzing. public class Main { public static void main(String[] args) { int tasodifiy=(int)(Math.random()*(100-1+1)+1); System.out.println("1 va 100 sonlari orasidan tasodiy son olamiz"+tasodifiy); } } Foydalanuvchi ikkita qiymat kiritadi, ularning kattasini topuvchi dastur tuzing. import java.util.Scanner; public class Main {
Foydalanuvchi kiritgan harfni alfavitdagi aksini toping! Input: a Output: z Input: B Output: Y Input: x Output: c import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Harf kiriting: "); char x = scanner.next().charAt(0); char aksiniTop = (char) (x + ('a' <= x && x <= 'z' ? -32 : 32)); System.out.println("Aksincha harf: " + aksiniTop); } } A va B son berilgan! A-B dan A+B gacha bo’lgan sonlarning faqat juftlarini yig’indisini topuvchi dastur tuzing. import java.util.Scanner; public class Main {
Foydalanuvchi nomanfiy son kiritadi. Shuning raqamlarini so’z tarzda ketma-ket chiqaring (xuddi rasmdagidek). import java.util.Scanner; public class Main { private static final String[] ONLAR = {"", "o'n", "yigirma", "o'ttiz", "qirq", "ellik", "oltmish", "yetmish", "sakson", "to'qson"}; private static final String[] BIRLAR = {"nol", "bir", "ikki", "uch", "to'rt", "besh", "olti", "yetti", "sakkiz", "to'qqiz"}; public static void main(String[] args) { Scanner scanner = new Scanner(System.in); System.out.print("Istalgan noma'lum sonni kiriting: "); int son = scanner.nextInt(); if (son < 0) { System.out.print("minus "); son = -son; } if (son == 0) { System.out.println(BIRLAR[0]); return; } String s = " "; if ((son / 1000000) > 0) { s += soni(son / 1000000) + " million "; son %= 1000000; } if ((son / 1000) > 0) { s += soni(son / 1000) + " ming "; son %= 1000; } if ((son / 100) > 0) { s += soni(son / 100) + " yuz "; son %= 100; } if (son > 0) { if (son < 10) { s += BIRLAR[son]; } else if (son < 20) { s += ONLAR[son - 10]; } else { s += ONLAR[son / 10] + " " + BIRLAR[son % 10]; } } System.out.println(s); } private static String soni(int n) { return ((n > 0) ? soni(n) : "") + soni(n); } } Download 17.96 Kb. Do'stlaringiz bilan baham: |
ma'muriyatiga murojaat qiling