6- BILET
1-masala
Foydalanuvchi 10 ta sondan iborat array va bitta n soni kiritadi. Shu n ta soni array ichida necha marta uchrashini toping.
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Array hajmini kiriting: ");
int n = input.nextInt();
int[] arr = new int[n];
System.out.println(n + " ta sondan iborat sonlarni kiriting: ");
for (int i = 0; i < n; i++) {
arr[i] = input.nextInt();
}
System.out.print("Qidirilayotgan sonni kiriting: ");
int x = input.nextInt();
int miqdor = 0;
for (int i = 0; i < n; i++) {
if (arr[i] == x) {
miqdor++;
}
}
System.out.println("Natija: " + miqdor + " marta uchrashdi.");
input.close();
}
}
2-masala
public class Misol{
public static void main(String[] args){
for(int i=1; i<6; i++ ){
for(int j=1; j<=i; j++) {
System.out.print("*");
}
System.out.println();
}
}
}
3-masala
Foydalanuvchi tomonidan qabul qilingan string tipidagi qiymatning barcha harflari kichik harf bilan ko’rinsin.
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.print("Matn kiriting: ");
String str = input.nextLine();
String kichikStr = str.toLowerCase();
System.out.println("Yuqoridagi matn kichik harflarda ko'rsatilgan holda:");
System.out.println(kichikStr);
input.close();
}
}
4-masala
Kiritilgan sondan 0 gacha sonlarni taqdim etuvchi recursive funksiya tuzing.
public class Main {
public static void main(String[] args) {
int n = 10;
sonidan (n);
}
public static void sonidan (int n) {
if (n < 0) {
return;
}
System.out.print(n + " ");
sonidan (n - 1);
}
}
5-masala. Human nomli class e’lon qiling va first_name last_name age nomli atributlari bo’lsin class da bitta full_name() nomli method e’lon qiling va u first_name va last_name ni bitta string qilib qaytarsin.
Dostları ilə paylaş: |