Javob: import java util. Random


Download 281.17 Kb.
Sana10.02.2023
Hajmi281.17 Kb.
#1185236
Bog'liq
1 amaliy ish


1-amaliy topshiriq
12-variant
Savol: a[n][m] massiv elementlarini [-100; 100] oraliqdagi tasodifiy sonlar bilan to’ldiring. Bu massiv elementlaridan 3 ga va 11 ga bo’linadiganlarining yig’indisi toping.
Javob:
import java.util.Random;
import java.util.Scanner;

public class Main {
public static void main(String[] args) {
int n,m;
Scanner scanner =new Scanner(System.in);
n = scanner.nextInt();
scanner =new Scanner(System.in);
m = scanner.nextInt();
int [][] a = new int[n][m];
Random random = new Random();
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
a[i][j] = random.nextInt(200)-100;
}
}
int s=0;
for (int[] ints : a) {
for (int anInt : ints) {
if ((anInt%3==0 || anInt%11==0)&& anInt!=0 ){
s+=anInt;
System.out.println(anInt);
}

}

}

System.out.println(s);

}
}


Download 281.17 Kb.

Do'stlaringiz bilan baham:




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling