Boa tarde, estou tentando resolver um exercicio sobre arrays(vetores e matrizes).Nele eu preciso declarar 2 vetores(linhas e colunas) e uma matriz que irá gerar um valor baseado nas linhas e colunas, porém não tenho conhecimento de como funciona 100% uma matriz, tentei fazer de algumas formas assistindo algumas videos aulas e nao deu certo. segue em anexo o programa que fiz:
public class ProjetoFinal {
public static void main(String[] args) {
int linhas, colunas;
int vetor1[];
int vetor2[];
System.out.println("Informe o número de linhas : ");
linhas = (new Scanner(System.in)).nextInt();
System.out.println("Informe o número de colunas : ");
colunas = (new Scanner(System.in)).nextInt();
vetor1 = new int[linhas];
vetor2 = new int[colunas];
System.out.println();
for(int i=0;i<vetor1.length;i++) {
System.out.print (" " + (i+1));
}
for(int j=0;j<vetor2.length;j++) {
System.out.println();
System.out.println(j+1);
}
}
Acho que me expressei incorretamente, na imagem abaixo sobre a impressão do programa eu preciso gerar um o resultado de cada linha e coluna (1,1) )(1,2) e assim por diante, porém o usuário que utilizar o programa que irá informar esses valores. Minha dúvida seria de como fazer o for e etc. Obrigado!
public static void main(String[] args) {
int linhas, colunas;
int vetor1[];
int vetor2[];
int matriz[][];
System.out.println("Informe o número de linhas : ");
linhas = (new Scanner(System.in)).nextInt();
System.out.println("Informe o número de colunas : ");
colunas = (new Scanner(System.in)).nextInt();
vetor1 = new int[linhas];
vetor2 = new int[colunas];
matriz = new int[linhas][colunas];
for (int i =0; i< matriz.length; i++) {
for (int j = 0; j < matriz[j].length; j++) {
System.out.print("Informe o valor da célula ("+i+", "+j+"): ");
matriz[i][j] = (new Scanner(System.in)).nextInt();
}
for(int l=0;l<vetor1.length;l++) {
System.out.print (" " + (l+1));
}
{
}
for(int n=0;n<vetor2.length;n++) {
System.out.println();
System.out.println(n+1);
}
}
{}}}