Leonel_G

Modulo

Sep 10th, 2021
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.87 KB | None | 0 0
  1. import java.util.*;
  2. public class Modulo {
  3.     public static int validarNumero(Scanner valorIngresado, String mensaje) {
  4.         int numero;
  5.         String linea;
  6.         while (true) {
  7.             try {
  8.                 System.out.println(mensaje);
  9.                 linea = valorIngresado.nextLine();
  10.                 numero = Integer.parseInt(linea);
  11.                 break;
  12.             } catch (Exception e) {
  13.                 System.out.println("''ERROR..! Ingrese un Numero Positivo''");
  14.             }
  15.         }
  16.         return numero;
  17.     }
  18.     public static int elegirOpcion(Scanner opcion , String mensaje){
  19.         int numero;
  20.         String linea;
  21.         while (true) {
  22.             try {
  23.                 System.out.println(mensaje);
  24.                 linea = opcion.nextLine();
  25.                 numero = Integer.parseInt(linea);
  26.                 while(!(numero<=2 && numero>=1)){
  27.                     System.out.println("Opcion Incorrecta");
  28.                     System.out.println(mensaje);
  29.                     linea = opcion.nextLine();
  30.                     numero = Integer.parseInt(linea);
  31.                 }
  32.                 break;
  33.             } catch (Exception e) {
  34.                 System.out.println("''ERROR..! Ingrese un numero''");
  35.             }
  36.         }
  37.         return numero;
  38.     }
  39.     public static void cargarMatriz(int [][] x,Scanner entrada){
  40.         for (int i=0; i<3;i++){
  41.             for (int j=0;j<3;j++){
  42.                 System.out.println("ingrese valores de matriz");
  43.                 x[i][j]= Integer.parseInt(entrada.next());
  44.                
  45.             }
  46.            
  47.         }      
  48.     }
  49.     public static void mostrarMatriz(int[][]x){
  50.         for (int i=0; i<x.length;i++){
  51.             for (int j=0;j<x.length;j++){
  52.                 System.out.print(x[i][j]+" ");
  53.  
  54.             }
  55.             System.out.println("");  
  56.         }
  57.     }
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment