Compare commits

..
5 Commits
Author SHA1 Message Date
PC de clase bfbbfec86d Expresar mejor valor rand 2026-10-26 09:50:07 +01:00
PC de clase 96e2bed803 0 tambien es un numero valido 2026-10-26 09:47:37 +01:00
PC de clase d10caff96d Contraseñas sin StringBuilder 2026-10-23 09:57:26 +02:00
PC de clase 5e74e07543 Ejercicios Dados y contraseñas 2026-10-23 09:25:05 +02:00
PC de clase 2738c0c9b5 Ejercicio nota media 2026-10-22 13:41:10 +02:00
3 changed files with 72 additions and 0 deletions

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
import java.util.Random;
public class Dados {
public static void main(String[] args){
Random r = new Random();
final int TIRADAS = 50;
int total = 0, max = 0, min = 7;
for(int i = 0; i < TIRADAS; i++){
int dado = r.nextInt(6) + 1;
total += dado;
if(dado > max) max = dado;
if(dado < min) min = dado;
}
System.out.printf("El promedio es %.2f, el maximo es %d y el minimo %d\n", (double)total/TIRADAS, max, min);
}
}
+23
View File
@@ -0,0 +1,23 @@
import java.util.Random;
public class GeneradorContraseñas {
public static void main(String[] args){
Random r = new Random();
int len = r.nextInt(12 + 1 - 8) + 8; // 8-12
for(int i = 0; i < len; i++) {
switch (r.nextInt(3)) {
case 0: // Dígito
System.out.printf("%d", r.nextInt(10));
break;
case 1: // Minúscula
System.out.printf("%c", r.nextInt(26) + (int) ('a'));
break;
case 2: // Mayúscula
System.out.printf("%c", r.nextInt(26) + (int) ('A'));
break;
default:
}
}
System.out.println();
}
}
+33
View File
@@ -0,0 +1,33 @@
// Tenemos una clase de 40 alumnos que tienen 7 asignaturas cada uno de ellos.
// Haz un porgrama que pregunte la nota de cada asignatura para cada alumno y nos
// diga la nota media de cada asignatura, así como el porcentaje de aprobados
import java.util.*;
public class NotaMedia {
static void main(String[] args) {
Scanner sc = new Scanner(System.in);
final int ALUMNOS = 40;
final int ASIGNATURAS = 7;
for (int i = 0; i < ASIGNATURAS; i++) {
int suspensos = 0;
double notaMedia = 0;
for (int j = 0; j < ALUMNOS;) {
System.out.printf("Qué ha sacado el alumno %2d en la asignatura %d?\n", j, i);
double nota = 0;
try {
nota = sc.nextDouble();
} catch (InputMismatchException e){
System.out.println("ERROR: Pon un número decimal válido");
continue;
} catch (Exception e){
System.out.println("ERROR: el programa ha salido con una exception" + e);
}
if (nota < 5) suspensos++;
notaMedia += nota;
j++;
}
System.out.printf("La nota media de la clase en la asignatura %d es %.2f\n", i, notaMedia / ALUMNOS);
}
}
}