Compare commits
9
Commits
296ce2f729
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bfbbfec86d | ||
|
|
96e2bed803 | ||
|
|
d10caff96d | ||
|
|
5e74e07543 | ||
|
|
2738c0c9b5 | ||
|
|
42030706b4 | ||
|
|
8b3b337b03 | ||
|
|
5129dd9415 | ||
|
|
8ee32e659d |
No files matched your search
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,7 +2,7 @@ public class EstructuraRepetitiva2 {
|
|||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
for (int i = 1; i <= 9; i++) {
|
for (int i = 1; i <= 9; i++) {
|
||||||
for (int j = 1; j <= 9; j++) {
|
for (int j = 1; j <= 9; j++) {
|
||||||
System.out.printf("%2d x %2d = %3d\n", i, j, i*j);
|
System.out.printf("%2d x %2d = %2d\n", i, j, i*j);
|
||||||
}
|
}
|
||||||
System.out.println("--------------");
|
System.out.println("--------------");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,18 @@ public class EstructuraRepetitiva3_2 {
|
|||||||
static void main(String[] args) {
|
static void main(String[] args) {
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
System.out.println("Introduce un número entero: ");
|
System.out.println("Introduce un número entero: ");
|
||||||
int n = sc.nextInt();
|
|
||||||
|
int n = 0;
|
||||||
|
try{
|
||||||
|
n = sc.nextInt();
|
||||||
|
} catch (Exception e) {
|
||||||
|
System.out.println("La lectura de input ha lanzado la exception" + e + "\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (n <= 4){
|
||||||
|
System.out.println("El numero tiene que ser mayor que 4");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// si compuestos[n] == true, el número es compuesto
|
// si compuestos[n] == true, el número es compuesto
|
||||||
boolean[] compuestos = new boolean[n + 1];
|
boolean[] compuestos = new boolean[n + 1];
|
||||||
|
|||||||
@@ -6,9 +6,8 @@ public class EstructuraRepetitiva4 {
|
|||||||
System.out.println("Introduce un número entero: ");
|
System.out.println("Introduce un número entero: ");
|
||||||
int n = sc.nextInt();
|
int n = sc.nextInt();
|
||||||
|
|
||||||
for (int i = 3; i <= n; i++) {
|
for (int i = 3; i <= n; i+=3) {
|
||||||
boolean primero = true; // Para poner la , bien
|
boolean primero = true; // Para poner la , bien
|
||||||
if (i % 3 == 0) {
|
|
||||||
System.out.printf("Múltiplo=%d divisores del %d: (", i, i);
|
System.out.printf("Múltiplo=%d divisores del %d: (", i, i);
|
||||||
for (int j = 1; j <= i; j++) {
|
for (int j = 1; j <= i; j++) {
|
||||||
if (i % j == 0) {
|
if (i % j == 0) {
|
||||||
@@ -19,7 +18,6 @@ public class EstructuraRepetitiva4 {
|
|||||||
}
|
}
|
||||||
System.out.print(")\n");
|
System.out.print(")\n");
|
||||||
}
|
}
|
||||||
}
|
|
||||||
sc.close();
|
sc.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -21,8 +21,10 @@ public class EstructuraRepetitiva5 {
|
|||||||
}
|
}
|
||||||
if (carga >= CARGA_MAXIMA) {
|
if (carga >= CARGA_MAXIMA) {
|
||||||
System.out.println("El camión ha alcanzado el peso máximo");
|
System.out.println("El camión ha alcanzado el peso máximo");
|
||||||
|
System.out.printf("Te has pasado por %.2fKg\n", CARGA_MAXIMA - carga);
|
||||||
} else {
|
} else {
|
||||||
System.out.println("El mueble ya no cabe en el camión");
|
System.out.println("El mueble ya no cabe en el camión");
|
||||||
|
System.out.printf("Te has pasado por %.2fm3\n", VOLUMEN_MAXIMO - volumen);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user