Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- public class Helper {
- //validar numeros
- public static int validarNumero(Scanner valorIngresado, String mensaje) {
- int numero;
- String linea;
- while (true) {
- try {
- System.out.println(mensaje);
- linea = valorIngresado.nextLine();
- numero = Integer.parseInt(linea);
- break;
- } catch (Exception e) {
- System.out.println("''ERROR..! Ingrese un Numero Positivo''");
- }
- }
- return numero;
- }
- //validar opcion random o manual
- public static int elegirOpcion(Scanner opcion , String mensaje){
- int numero;
- String linea;
- while (true) {
- try {
- System.out.println(mensaje);
- linea = opcion.nextLine();
- numero = Integer.parseInt(linea);
- while(!(numero<=2 && numero>=1)){
- System.out.println("Opcion Incorrecta");
- System.out.println(mensaje);
- linea = opcion.nextLine();
- numero = Integer.parseInt(linea);
- }
- break;
- } catch (Exception e) {
- System.out.println("''ERROR..! Ingrese un numero''");
- }
- }
- return numero;
- }
- //validar que se ingrese solamente letras primera parte
- public static String cargarLetra(Scanner entrada,String mensaje){
- System.out.println(mensaje);
- String linea=entrada.nextLine();
- while(validarLetras(linea)){
- System.out.println("''ERROR'' No Ingresar Numeros");
- System.out.println(mensaje);
- linea=entrada.nextLine();
- }
- return linea;
- }
- //validar que se ingrese solamente letras segunda parte
- public static boolean validarLetras(String linea) {
- for (int x = 0; x < linea.length(); x++) {
- char c = linea.charAt(x);
- if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
- return true;
- }
- }
- return false;
- }
- //Genera caracter random
- public static String caracterRandom() {
- Random random = new Random();
- char caracterRandom = (char)(random.nextInt(26) + 'a');
- System.out.println("Caracter generado: "+ caracterRandom);
- String caracter = String.valueOf(caracterRandom);
- return caracter;
- }
- //Genera Nombre Random
- public static String nombreRandom(){
- int random;
- String [] nombre ={"Fernanda","Lorena ","Martín ","Sara","Pedro","Gabriel","Gerardo","Lis","Catriel","Camila"};
- random = (int) (Math.random() * nombre.length);
- return nombre[random];
- }
- //Cargar correo random
- public static String correoRandom(){
- int random;
- String [] correo ={"Marcopolo@gmail.com","grein123@hotmail.com ","dr-bles@hotmail.com ","darkBoss-123@gmal.com",
- "gener@gmail.com","runu-wuw@hotmail.com","bro10@gmail.com","Replay@hotmail.com","dowH@gmail.com.es","shawer@yahoo.com"};
- random = (int) (Math.random() * correo.length);
- return correo[random];
- }
- //Generar correo random 2
- public static void correoRandom2(ArrayList<String> correos,Scanner entrada){
- int random;
- String opcion ="s";
- String [] correo ={"Marcopolo@gmail.com","grein123@hotmail.com ","dr-bles@hotmail.com ","darkBoss-123@gmal.com",
- "gener@gmail.com","runu-wuw@hotmail.com","bro10@gmail.com","Replay@hotmail.com","dowH@gmail.com.es","shawer@yahoo.com"};
- while (opcion.equalsIgnoreCase("s")){
- random = (int) (Math.random() * correo.length);
- System.out.println("¿agregar otro correo?");
- opcion = entrada.nextLine();
- correos.add(correo[random]);
- }
- }
- //sin uso aun
- public static void cargarMatriz(int [][] x,Scanner entrada){
- for (int i=0; i<3;i++){
- for (int j=0;j<3;j++){
- System.out.println("ingrese valores de matriz");
- x[i][j]= Integer.parseInt(entrada.next());
- }
- }
- }
- //sin uso aun
- public static void mostrarMatriz(int[][]x){
- for (int i=0; i<x.length;i++){
- for (int j=0;j<x.length;j++){
- System.out.print(x[i][j]+" ");
- }
- System.out.println("");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement