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);
}
}
Do'stlaringiz bilan baham: |