Ejercicios Java For Do While
Ejercicios Java For Do While
Ejercicio 1 (for)
package tzejercicio01;
Ejercicio 2 (while)
Package tzejercicio02;
import java.util.Scanner;
public class Tzejercicio02 {
Ejercicio 7 (while)
package tzejercicio07;
import java.util.Scanner;
public class Tzejercicio07 {
public static void main(String[] args) {
// TODO code application logic here
System.out.println("Programa para sumar varios números");
Scanner tzscanner = new Scanner(System.in);
int tzacumulador = 0;
int tznuevoNumero = 0;
while (tznuevoNumero >= 0) {
System.out.println("Insertar un nuevo número a sumar o -1 para
finalizar");
tznuevoNumero = tzscanner.nextInt();
if (tznuevoNumero > 0) {
tzacumulador = tzacumulador + tznuevoNumero;}}
System.out.println("Total: " + tzacumulador);
}
}
Ejercicio 8 (do-while)
package tzejercicio08;
import java.util.Scanner;
public class Tzejercicio08 {
Ejercicio 9 (do-while)
package tzejercicio09;
import java.util.Scanner;
public class Tzejercicio09 {
public static void main(String[] args) {
// TODO code application logic here
int tzNota = 0, tzCont1 = 0,tzCont2 = 0;
Scanner tzTeclado = new Scanner(System.in);
do {
System.out.println("Ingrese la nota del alumno menor a 20 y digite 0 para
terminer la accion ");
tzNota = tzTeclado.nextInt();
if (tzNota>=11) {
tzCont1=tzCont1+1;
} else if (tzNota>0){
tzCont2=tzCont2+1;
}
} while (tzNota != 0);
System.out.println("La cantidad de alumnos que tienen notas mayores o iguales a
11 son : " + tzCont1);
System.out.println("La cantidad de alumnos que tienen notas menores a 11 son:
"+tzCont2);
}
}
Ejercicio 10 (do-while)
package tzejercicio10;
import java.util.Scanner;
public class Tzejercicio10 {
public static void main(String[] args) {
// TODO code application logic here
Scanner tzentrada=new Scanner(System.in);
int tzvalor;
do {
System.out.print("Ingrese un valor entre 0 y 50 (0 finaliza):");
tzvalor=tzentrada.nextInt();
if (tzvalor>=50) {
System.out.println("Es de 3 dígitos.");
} else {
if (tzvalor>=10) {
System.out.println("Es de 2 dígitos.");
} else {
System.out.println("Es de 1 dígito.");
}
}
} while (tzvalor!=0);
}
}
Ejercicio 11 (while)
package tzejercicio11;
public class Tzejercicio11 {
public static void main(String[] args) {
// TODO code application logic here
int tzx = 10;
while( tzx <= 50 ) {
System.out.print("todos los numeroes menores o igual que x : " + tzx );
tzx++;
System.out.print("\n");
} } }
Ejercicio 12 (for)
package tzejercicio12;
public class Tzejercicio12 {
public static void main(String[] args) {
// TODO code application logic here
String[] tzdias = {"Lunes", "Martes", "Miercoles", "Jueves", "Viernes",
"Sabado", "Domingo"};
do {
System.out.println("¿Hoy es mi cumpleaños?");
} while(tzi);
System.out.println(tzi);
}
}
Ejercicio 14 (while)
package tzejercicio14;
public class Tzejercicio14 {
public static void main(String[] args) {
// TODO code application logic here
int tzi = 0;
while (true) {
tzi++;
if (tzi==9) { break;}
}
}
}
Ejercicio 15 (for)
package tzejercicio15;
Ejercicio 16 (for)
package tzejercicio16;
Ejercicio 19 (do-while)
package tzejercicio19;
import java.util.Scanner;
public class Tzejercicio19 {
public static void main(String[] args) {
// TODO code application logic here
int tzx;
Scanner tzentrada=new Scanner(System.in);
System.out.println("Ingresar un numero menor a 20 y mayor a 0");
tzx=tzentrada.nextInt();
do{
System.out.print("numero menor que tzx : " + tzx );
tzxx++;
System.out.print("\n");
}while( tzxx < 20 );
}
}
Ejercicio 20 (while)
package tzejercicio20;
while(tzi != 0) {
System.out.println("HUNAR"); // No se ejecuta.
}
do {
System.out.println("HUNAR-TAIPE"); // Se ejecuta una vez.
} while(tzi != 0);
}
}