Advertisement
valentina_cobo

Untitled

Feb 10th, 2021 (edited)
310
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.71 KB | None | 0 0
  1. public class parcial {
  2.     int f, c, B[];
  3.    
  4.    
  5.     public void tamanio(){
  6.         String ent = JOptionPane.showInputDialog("Ingrese la cantidad de filas:");
  7.         int f = Integer.parseInt(ent);
  8.         ent = JOptionPane.showInputDialog("Ingrese la cantidad de columnas:");
  9.         int c = Integer.parseInt(ent);
  10.        
  11.         B = new int[c];
  12.     }
  13.    
  14.     public void rellenar(int matriz[][]){
  15.         for (int f = 0; f < matriz.length; f++) {
  16.             for (int c = 0; c < matriz[0].length; c++) {
  17.                 matriz[f][c] = 1 + (int)(Math.random() * 100);
  18.             }
  19.         }
  20.     }
  21.    
  22.     public void imprimirArray(int A[][], int x){
  23.         System.out.println(frecuencia(A, x));
  24.        
  25.     }
  26.     public void imprimirMat(int matriz[][]){
  27.         String salida = "";
  28.        
  29.         for (int f = 0; f < matriz.length; f++) {
  30.             for (int c = 0; c < matriz[0].length; c++) {
  31.                 System.out.print(matriz[f][c] + " ");
  32.                 salida+=matriz[f][c] + " ";
  33.             }
  34.             System.out.println();
  35.             salida+="\n";
  36.         }
  37.         JOptionPane.showMessageDialog(null, salida);
  38.     }
  39.     public int [] frecuencia(int A[][], int x){
  40.         rellenar(A);
  41.         String ent = JOptionPane.showInputDialog("Ingrese el dato a buscar");
  42.         x = Integer.parseInt(ent);
  43.         int frec = 0;
  44.         int num = 0;
  45.         for (int f = 0; f < A.length; f++) {
  46.             for (int c = 0; c < A[0].length; c++) {
  47.                 if (f == num) {
  48.                         if(A[f][c] == x)
  49.                             B[c]= frec++;
  50.                         else B[c]=frec;
  51.                     }
  52.                 num++;
  53.                 if (num==this.f) break;
  54.             }            
  55.         }
  56.        
  57.         return B;
  58.     }
  59.    
  60.     public static void main(String[] args) {
  61.         parcial obj = new parcial();
  62.         obj.tamanio();
  63.         System.out.println(obj.frecuencia(A, 0));
  64.        
  65.        
  66.     }
  67. }
  68.  
  69.  
  70.  
  71.  
  72. punto c para probar
  73.   public void imprimir(){
  74.         int contador = 0;
  75.         int suma = 0;
  76.         for (int i = 0; i < n; i++) {
  77.             suma = contador + A[i];
  78.             if (A[i] != 0)System.out.println(A[i]);
  79.         }
  80.         if (suma == 0)
  81.             JOptionPane.showMessageDialog(null, "A esta vacio");  
  82.     }
  83.  
  84.  
  85. puntod para probar
  86.  public void imprimir_alrevez(){
  87.         int contador = 0;
  88.         int suma = 0;
  89.         for (int i = 0; i < n; i++) {
  90.             suma = contador + A[i];
  91.             if (A[n-1] != 0) System.out.println(A[n-1]);
  92.             n--;
  93.             if (n == 0) break;
  94.         if (suma == 0)
  95.             JOptionPane.showMessageDialog(null, "A esta vacio");  
  96.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement