PROGRAMA RESUELTO #1
1
2 public static void main (String args [])
3 {
4 int n=0;
while(n<10)
5 {
6 n++;
7 System.out.print(n+"\n");
8
9 }
1 }
0
1
public static void main (String args [])
2 {
3
4 int n=0;
5 do{
6 n++;
System.out.print(n+" ");
7
}while(n<10);
8 }
9
1
public static void main (String args [])
2 {
3
4 int n=0;
5 for(int i=1;i<=10;i++)
6 {
System.out.print(i+" ");
7
}
8 }
9
PROGRAMAS PROPUESTOS #1
a) 1,3,5,7,21
b) 30,27,24,21,hasta 1
PROGRAMAS RESUELTOS #2
1
2
3
4
5
6
7
import java.util.Scanner;
8
9
public class Ejemplo
1
{
0
11
public static void main(String[] args)
1
{
2
Scanner scan = new Scanner(System.in);
1
int n, x, cp = 0, ci = 0;
3
System.out.print("Ingrese la cantidad de numeros a revisar:
1
");
4
n = scan.nextInt();
1 for (int i = 1; i <= n; i++)
5 {
1 System.out.print(i + ") Ingrese un numero: ");
6 x = scan.nextInt();
1 if (x % 2 == 0)
7 cp++;
1 else
8 ci++;
1 }
9 System.out.println("La cantidad de pares son: " + cp);
2 System.out.println("La cantidad de impares son: " + ci);
0 }
2 }
1
2
2
2
3
2
4
1 import java.util.Scanner;
2
3 public class Ejemplo
4 {
5
6 public static void main(String[] args)
7 {
8 Scanner scan = new Scanner(System.in);
9 int n, x, cp = 0, cn = 0, c=0;
10 System.out.print("Ingrese la cantidad de numeros a revisar: ");
11 n = scan.nextInt();
12 for (int i = 1; i <= n; i++)
13 {
14 System.out.print(i + ") Ingrese un numero: ");
15 x = scan.nextInt();
16 if (x==0)
17 c++;
18 else
19 {
20 if(x>0)
21 cp++;
22 else
23 cn++;
24
25 }
26 }
27 System.out.println("La cantidad de positivos son: " + cp);
28 System.out.println("La cantidad de negativos son: " + cn);
29 System.out.println("La cantidad de ceros son: " + c);
30 }
31}