Poderiam comentar ou arrumar os comentários por favor, to querendo entender essas linhas!!
/**
* Write a description of class Matriz here.
*
* @author (Rigel Areco)
* @version (1.0)
*/
public class Matriz
{
// instance variables - replace the example below with your own
public int x[][];// criando matriz
public int n; //declarando várialvel n
public Matriz() //metodo construtor
{
n = 0; //está iniando a variavel n com valor de 0
}
public Matriz(int t) //metodo construtor e criando uma várialvel t do tipo inteiro
{
x = new int[t][t]; // está falando que a matriz terá o número de colunas e linhas = t
n = t;
}
public void setX(int l, int c, int v) //criando medoto set
{
if(l < n && c < n)
{
x[l][c] = v;
}
}
public int getX(int l, int c)
{
return x[l][c];
}
public void geraIdentidade(int g)
{
//x = new int[g][g];
//n = g;
for(int i = 0; i < g; i++)
{
for(int j = 0; j <g; j++)
{
if(i == j)
{
setX(i, j, 1);
}
else
{
setX(i, j, 0);
}
}
}
}
public void geraMatriz2(int g)
{
for(int i = 0; i < g; i++)
{
for(int j = 0; j <g; j++)
{
setX(i, j, i+1);
}
}
}
public void geraMatriz3(int g)
{
int v1 = 1;
for(int i = 0; i < g; i++)
{
for(int j = 0; j <g; j++)
{
setX(i, j, v1);
v1+=1;
}
}
}
public void exibir(int g)
{
String z="";
for(int i = 0; i < g; i++)
{
for(int j = 0; j < g; j++)
{
z += getX(i,j)+" ";
}
System.out.println(z);
z = "";
}
}
}
/**
* Write a description of class Principal here.
*
* @author (your name)
* @version (a version number or a date)
*/
public class Principal
{
// instance variables - replace the example below with your own
/**
* Constructor for objects of class Principal
*/
public static void main(String args[])
{
Matriz m = new Matriz(7);
System.out.println("Matriz Identidade");
m.geraIdentidade(7);
m.exibir(7);
System.out.println("Matriz exercicio 2");
m.geraMatriz2(7);
m.exibir(7);
System.out.println("Matriz exercicio 3");
m.geraMatriz3(7);
m.exibir(7);
}
}