1 va 100 sonlari orasidan tasodifiy sonlarni chiqaruvchi dastur tuzing


Download 17.96 Kb.
Sana13.05.2023
Hajmi17.96 Kb.
#1456883
Bog'liq
Jumayev Asilbek MI-303


  1. 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);
}
}

  1. Foydalanuvchi ikkita qiymat kiritadi, ularning kattasini topuvchi dastur tuzing.

import java.util.Scanner;

public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Birinchi sonni kiriting: ");
int a1 = scanner.nextInt();
System.out.print("Ikkinchi sonni kiriting: ");
int a2 = scanner.nextInt();
int kattasiniekrangachiqar = a1 > a2 ? a1 : a2;
System.out.println("Katta son: " + kattasiniekrangachiqar);
}
}


  1. 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);
}
}

  1. 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 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("A ni kiriting: ");
int a = scanner.nextInt();
System.out.print("B ni kiriting: ");
int b = scanner.nextInt();
int yigindi = 0;
for (int i = a - b; i <= a + b; i++) {
if (i % 2 == 0) {
yigindi += i;
}
}
System.out.println("Juft sonlar yig'indisi: " + yigindi);
}
}


  1. 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'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling