-
Lenguaje
Java usando Scanner
-
Descripción
Se ingresan N números enteros, se quiere saber cuantos múltiplos a 5 de han ingresado y cuantos múltiplos a 2 se han ingresado.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import java.util.Scanner;
public class MultiplosDe2Y5 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, multiplos_de_2, multiplos_de_5, n, un_numero;
multiplos_de_2 = 0;
multiplos_de_5 = 0;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.print("Ingresa el valor de un numero: ");
un_numero = in.nextInt();
in.nextLine();
if(un_numero%2==0)
multiplos_de_2=multiplos_de_2+1;
if(un_numero%5==0)
multiplos_de_5=multiplos_de_5+1;
System.out.println();
}
System.out.println("Valor de multiplos de 2: " + multiplos_de_2);
System.out.println("Valor de multiplos de 5: " + multiplos_de_5);
}
}
public class MultiplosDe2Y5 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int i, multiplos_de_2, multiplos_de_5, n, un_numero;
multiplos_de_2 = 0;
multiplos_de_5 = 0;
System.out.print("Ingresa el valor de n: ");
n = in.nextInt();
in.nextLine();
for (i=1; i<=n; i++) {
System.out.print("PROCESO " + i);
System.out.print("Ingresa el valor de un numero: ");
un_numero = in.nextInt();
in.nextLine();
if(un_numero%2==0)
multiplos_de_2=multiplos_de_2+1;
if(un_numero%5==0)
multiplos_de_5=multiplos_de_5+1;
System.out.println();
}
System.out.println("Valor de multiplos de 2: " + multiplos_de_2);
System.out.println("Valor de multiplos de 5: " + multiplos_de_5);
}
}