Ejercicios Dados y contraseñas
This commit is contained in:
1 parent
2738c0c9b5
commit
5e74e07543
2 files changed
+40
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,24 @@
|
|||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public class GeneradorContraseñas {
|
||||||
|
public static void main(String[] args){
|
||||||
|
Random r = new Random();
|
||||||
|
int len = r.nextInt(12-8) + 8;
|
||||||
|
StringBuilder resultado = new StringBuilder();
|
||||||
|
for(int i = 0; i < len; i++){
|
||||||
|
switch(r.nextInt(3)){
|
||||||
|
case 0: // Dígito
|
||||||
|
resultado.append(r.nextInt(9) + 1);
|
||||||
|
break;
|
||||||
|
case 1: // Minúscula
|
||||||
|
resultado.append((char)(r.nextInt(26) + (int)('a')));
|
||||||
|
break;
|
||||||
|
case 2: // Mayúscula
|
||||||
|
resultado.append((char)(r.nextInt(26) + (int)('A')));
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
}
|
||||||
|
}
|
||||||
|
System.out.println(resultado.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user