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;
- }
- //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