Ejercicios Resueltos de Programación en Java para Principiantes
Classified in Design and Engineering
Written on in
English with a size of 3.08 KB
Ejercicio 1
import java.util.Scanner;
public class Ejercicio1 {
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
int nota = 0;
while (nota != -1) {
System.out.println("Ingrese su nota del 1 al 20");
nota = leer.nextInt();
if (nota <= 20 && nota >= 18) {
System.out.println("A");
} else {
if (nota >= 16 && nota < 18) {
System.out.println("B");
} else {
if (nota >= 13 && nota < 16) {
System.out.println("C");
} else {
if (nota >= 10 && nota < 13) {
System.out.println("D");
} else {
if (nota < 10 && nota >= 0) {
System.out.println("E");
} else {
if (nota < 0 && nota >= -1) {
System.out.println("Has salido");
}
}
}
}
}
}
}
}
}Ejercicio 2
import java.util.Scanner;
public class Ejercicio2 {
public static void main(String[] args) {
Scanner leer = new Scanner(System.in);
int div = 0;
int numero = 0;
System.out.println("Dígame un número y le digo si es primo o no");
numero = leer.nextInt();
for (int i = 1; i <= numero; i++) {
if ((numero % i) == 0) {
div = (div + 1);
}
}
if (div > 2) {
System.out.println("El número no es primo");
} else {
System.out.println("El número es primo");
}
}
}Ejercicio 3
import java.util.Scanner;
public class Ejercicio3 {
public static void main(String[] args) {
int horaentrada = 0;
int horasalida = 0;
int preciototal = 0;
int tiempototal = 0;
System.out.println("Introduzca la hora de entrada");
Scanner leer = new Scanner(System.in);
horaentrada = leer.nextInt();
System.out.println("Introduzca la hora de salida");
horasalida = leer.nextInt();
tiempototal = (horasalida - horaentrada);
do {
if (tiempototal == 1) {
preciototal = preciototal + 3;
tiempototal = tiempototal - 1;
}
if ((tiempototal <= 3) && (tiempototal >= 1)) {
preciototal = preciototal + 2;
tiempototal = tiempototal - 1;
}
if (tiempototal > 3) {
preciototal = preciototal + 1;
tiempototal = tiempototal - 1;
}
} while (tiempototal > 0);
System.out.println("El precio total es: " + preciototal);
}
}