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,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