SHOW:
|
|
- or go back to the newest paste.
| 1 | import java.util.*; | |
| 2 | public class Helper {
| |
| 3 | //validar numeros | |
| 4 | public static int validarNumero(Scanner valorIngresado, String mensaje) {
| |
| 5 | int numero; | |
| 6 | String linea; | |
| 7 | while (true) {
| |
| 8 | try {
| |
| 9 | System.out.println(mensaje); | |
| 10 | linea = valorIngresado.nextLine(); | |
| 11 | numero = Integer.parseInt(linea); | |
| 12 | break; | |
| 13 | } catch (Exception e) {
| |
| 14 | System.out.println("''ERROR..! Ingrese un Numero Positivo''");
| |
| 15 | } | |
| 16 | } | |
| 17 | return numero; | |
| 18 | } | |
| 19 | //validar opcion random o manual | |
| 20 | public static int elegirOpcion(Scanner opcion , String mensaje){
| |
| 21 | int numero; | |
| 22 | String linea; | |
| 23 | while (true) {
| |
| 24 | try {
| |
| 25 | System.out.println(mensaje); | |
| 26 | linea = opcion.nextLine(); | |
| 27 | numero = Integer.parseInt(linea); | |
| 28 | while(!(numero<=2 && numero>=1)){
| |
| 29 | System.out.println("Opcion Incorrecta");
| |
| 30 | System.out.println(mensaje); | |
| 31 | linea = opcion.nextLine(); | |
| 32 | numero = Integer.parseInt(linea); | |
| 33 | } | |
| 34 | break; | |
| 35 | } catch (Exception e) {
| |
| 36 | System.out.println("''ERROR..! Ingrese un numero''");
| |
| 37 | } | |
| 38 | } | |
| 39 | return numero; | |
| 40 | } | |
| 41 | //validar que se ingrese solamente letras primera parte | |
| 42 | public static String cargarLetra(Scanner entrada,String mensaje){
| |
| 43 | System.out.println(mensaje); | |
| 44 | String linea=entrada.nextLine(); | |
| 45 | while(validarLetras(linea)){
| |
| 46 | System.out.println("''ERROR'' No Ingresar Numeros");
| |
| 47 | System.out.println(mensaje); | |
| 48 | linea=entrada.nextLine(); | |
| 49 | } | |
| 50 | return linea; | |
| 51 | } | |
| 52 | //validar que se ingrese solamente letras segunda parte | |
| 53 | public static boolean validarLetras(String linea) {
| |
| 54 | for (int x = 0; x < linea.length(); x++) {
| |
| 55 | char c = linea.charAt(x); | |
| 56 | if (!((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || c == ' ')) {
| |
| 57 | return true; | |
| 58 | } | |
| 59 | } | |
| 60 | return false; | |
| 61 | } | |
| 62 | ||
| 63 | //sin uso aun | |
| 64 | public static void cargarMatriz(int [][] x,Scanner entrada){
| |
| 65 | for (int i=0; i<3;i++){
| |
| 66 | for (int j=0;j<3;j++){
| |
| 67 | System.out.println("ingrese valores de matriz");
| |
| 68 | x[i][j]= Integer.parseInt(entrada.next()); | |
| 69 | ||
| 70 | } | |
| 71 | ||
| 72 | } | |
| 73 | } | |
| 74 | //sin uso aun | |
| 75 | public static void mostrarMatriz(int[][]x){
| |
| 76 | for (int i=0; i<x.length;i++){
| |
| 77 | for (int j=0;j<x.length;j++){
| |
| 78 | System.out.print(x[i][j]+" "); | |
| 79 | ||
| 80 | } | |
| 81 | System.out.println("");
| |
| 82 | } | |
| 83 | } | |
| 84 | } | |
| 85 |