Java - quiero que el metodo llamado "imprimirMatriz" me muestre los valores primos en 0

 
Vista:

quiero que el metodo llamado "imprimirMatriz" me muestre los valores primos en 0

Publicado por sebastian muñoz rios (1 intervención) el 09/03/2018 19:14:16
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
package m_dispersa;
import java.util.ArrayList;
class Nodo
{
    private int valor, fil, col;
    public Nodo sig;
    public Nodo(int valor, int fil, int col)
    {
        this.valor = valor;
        this.fil = fil;
        this.col = col;
        this.sig = null;
    }
    public int getValor()
    {
        return this.valor;
    }
    public int getFil()
    {
        return this.fil;
    }
    public int getCol()
    {
        return this.col;
    }
}
class Dispersa
{
    private Nodo cab, fin;
    private ArrayList<ArrayList<Integer>> mat = new ArrayList();
    private int cVal;
    private int cFC;
    public Dispersa(int cVal, int cFC)
    {
        int i;
        this.cVal = cVal;
        this.cFC = cFC;
        for(i = 0; i<cFC; i++)
        {
            mat.add(new ArrayList<Integer>());
            for(int j = 1; j <= cFC; j++)
                mat.get(i).add(0);
        }
    }
    public void llenaDispersa()
    {
        int i=0, f, c;
        while(i < cVal)
        {
            f = (int) (Math.random() * cFC);
            c = (int) (Math.random() * cFC);
            if(mat.get(f).get(c) == 0)
            {
                mat.get(f).set(c, (int)(Math.random() * 100) + 1);
                i++;
            }
        }
    }
    public void imprimirMatriz()
    {
        for(int i=0; i < cFC; i++)
        {
            for(int f = 0; f < cFC; f++)
                System.out.print(mat.get(i).get(f) +  "\t");
            System.out.println();
        }
    }
 
    public void crearLista()
    {
        int f, c;
        for(f = 0; f < cFC; f++)
        {
            for(c = 0; c < cFC; c++)
                if(mat.get(f).get(c) != 0)
                {
                    int v = mat.get(f).get(c);
                    Nodo nodo = new Nodo(v, f, c);
                    if(cab == null)
                    {
                        cab = nodo;
                        fin = nodo;
                    }
                    else
                    {
                        fin.sig = nodo;
                        fin = nodo;
                    }
                }
        }
    }
    public void mostrarLista()
    {
        if(cab != null)
        {
            Nodo p;
            p = cab;
            while(p != null)
            {
                System.out.print("[" + p.getValor() +
                                 "," + p.getFil() +
                                 "," + p.getCol() + "]");
                p = p.sig;
            }
        }
    }
}
public class M_dispersa
{
    public static void main(String[] args)
    {
        Dispersa dis = new Dispersa(8, 6);
        dis.llenaDispersa();
        dis.imprimirMatriz();
        dis.crearLista();
        dis.mostrarLista();
    }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder