Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class parcial {
- int f, c, B[];
- public void tamanio(){
- String ent = JOptionPane.showInputDialog("Ingrese la cantidad de filas:");
- int f = Integer.parseInt(ent);
- ent = JOptionPane.showInputDialog("Ingrese la cantidad de columnas:");
- int c = Integer.parseInt(ent);
- B = new int[c];
- }
- public void rellenar(int matriz[][]){
- for (int f = 0; f < matriz.length; f++) {
- for (int c = 0; c < matriz[0].length; c++) {
- matriz[f][c] = 1 + (int)(Math.random() * 100);
- }
- }
- }
- public void imprimirArray(int A[][], int x){
- System.out.println(frecuencia(A, x));
- }
- public void imprimirMat(int matriz[][]){
- String salida = "";
- for (int f = 0; f < matriz.length; f++) {
- for (int c = 0; c < matriz[0].length; c++) {
- System.out.print(matriz[f][c] + " ");
- salida+=matriz[f][c] + " ";
- }
- System.out.println();
- salida+="\n";
- }
- JOptionPane.showMessageDialog(null, salida);
- }
- public int [] frecuencia(int A[][], int x){
- rellenar(A);
- String ent = JOptionPane.showInputDialog("Ingrese el dato a buscar");
- x = Integer.parseInt(ent);
- int frec = 0;
- int num = 0;
- for (int f = 0; f < A.length; f++) {
- for (int c = 0; c < A[0].length; c++) {
- if (f == num) {
- if(A[f][c] == x)
- B[c]= frec++;
- else B[c]=frec;
- }
- num++;
- if (num==this.f) break;
- }
- }
- return B;
- }
- public static void main(String[] args) {
- parcial obj = new parcial();
- obj.tamanio();
- System.out.println(obj.frecuencia(A, 0));
- }
- }
- punto c para probar
- public void imprimir(){
- int contador = 0;
- int suma = 0;
- for (int i = 0; i < n; i++) {
- suma = contador + A[i];
- if (A[i] != 0)System.out.println(A[i]);
- }
- if (suma == 0)
- JOptionPane.showMessageDialog(null, "A esta vacio");
- }
- puntod para probar
- public void imprimir_alrevez(){
- int contador = 0;
- int suma = 0;
- for (int i = 0; i < n; i++) {
- suma = contador + A[i];
- if (A[n-1] != 0) System.out.println(A[n-1]);
- n--;
- if (n == 0) break;
- if (suma == 0)
- JOptionPane.showMessageDialog(null, "A esta vacio");
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement