AVTOBIOGRAFIYA tuzilib oxrida to`liq ma`lumotlar chiqsin.
Javob:
4. Natural n (n>999, n<9999) 4 xonali soni berilgan. Ushbu sonni palindrom ekanligini aniqlang. Palindrom son deb chapdan ham o`ngdan ham bir xil o`qiladigan songa aytiladi. Misol: 1221, 1001,3333,9889 lar palindrom songa misol bo`ladi.
Javob:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a,b,c,d,e,f;
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
c=a % 10;
d=(a % 100) / 10;
e=(a / 100) % 10;
f=a / 1000;
b=c*1000+d*100+e*10+f;
System.out.println(b);
if (b==a) {
System.out.println(a + " soni palindrom son");
} else {
System.out.println("Sonni xato kiritdingiz");
}
}
}
5. [1,999] oralig`idagi a son berilgan shu sonni teskari tartibda chiqaring.Misol: 123 javob: 321.
Misol:
1)a=12 natija : 21
2)a=126 natija : 621
3)a=100 natija: 1 // 001 soni yo`q
Javob:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a;
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
if (1 <= a && a <= 999) {
if (a <= 9) {
System.out.println(a % 10);
}
if (10 <= a && a <= 99) {
System.out.println((a % 10) * 10 + a / 10);
}
if (100 <= a) {
System.out.println((a % 10) * 100 + ((a % 100) / 10) * 10 + a / 100);
}
} else {
System.out.println("Son xato");
}
}
}
6. [10,70] oralig`ida a son yoshi berilgan shuni so`zda chiqaring. Agar a soni [10,70] oralig`iga kirmasa “Xato Raqam” so`zi chiqsin
Javob:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int a, yosh, raqam;
Scanner scanner = new Scanner(System.in);
a = scanner.nextInt();
if (a >= 10 && a <= 70) {
raqam = a % 10;
yosh = a / 10;
if (yosh == 1) System.out.print("O'n");
if (yosh == 2) System.out.print("Yigirma");
if (yosh == 3) System.out.print("O'ttiz");
if (yosh == 4) System.out.print("Qirq");
if (yosh == 5) System.out.print("Ellik");
if (yosh == 6) System.out.print("Oltmish");
if (yosh == 7) System.out.print("Yetmish");
if (raqam == 1) System.out.print(" bir");
if (raqam == 2) System.out.print(" ikki");
if (raqam == 3) System.out.print(" uch");
if (raqam == 4) System.out.print(" to'rt");
if (raqam == 5) System.out.print(" besh");
if (raqam == 6) System.out.print(" olti");
if (raqam == 7) System.out.print(" yetti");
if (raqam == 8) System.out.print(" sakkiz");
if (raqam == 9) System.out.print(" to'qqiz");
System.out.println(" yoshda");
} else {
System.out.println("Xato raqam");
}
}
}
7. Kiritgan son tub yoki tub emasligini aniqlovchi dastur tuzing
Javob:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
int count = 0;
Scanner scanner = new Scanner(System.in);
System.out.print("n= ");
int n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
if (n % i == 0) {
count++;
}
}
if (count == 2) {
System.out.println("tub son");
} else {
System.out.println("tub son emas");
}
}
}
8. Kiritgan n sonigacha bo’lgan tub sonlar to’plamini ko’rsating
Javob:
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("n= ");
int n = scanner.nextInt();
for (int i = 1; i <= n; i++) {
int count = 0;
for (int j = 1; j <= i; j++) {
if (i % j == 0) {
count++;
}
}
if (count == 2) {
System.out.println(i);
}
}
}
}
Do'stlaringiz bilan baham: |