2
How do I enter, asking the user through the class Scanner
, the size of the matrix and it tells me the column and row numbers you want, and then print the values, without using methods? I tried but it’s making a mistake:
import java.util.Scanner;
public class Matriz {
int matriz[][], linha, coluna;
public Matriz(int linha, int coluna){
matriz = new int [linha][coluna];
this.linha = linha;
this.coluna = coluna;
}
public void Inserir(){
Scanner entrada = new Scanner(System.in);
for(int x=0; x < linha; x++){
for(int y=0; y < coluna; y++){
System.out.println("matriz ["+x+"]["+y+"] =");
matriz[x][y]= entrada.nextInt();
}//fim for
}//fim for
}//fim inserir
public void Imprimir(){
for(int x=0; x < linha; x++){
for(int y=0; y < coluna; y++){
System.out.print(matriz[x][y]+"\t");
}//fim for
System.out.println();//apenas para quebrar linha
}//fim for
}
public static void main(String [] args){
Scanner entrada = new Scanner(System.in);
int linha=0, coluna =0;
System.out.println("Informe a quantidade de linhas da matriz");
linha = entrada.nextInt();
System.out.println("Informe a quantidade de colunas da matriz");
coluna = entrada.nextInt();
Matriz mat = new Matriz(linha, coluna);
mat.Inserir();
mat.Imprimir();
}
}
Method-free.
What mistake? Try to improve your question?
– rubStackOverflow
I can’t type numbers.
– user39783
Do you want the user to enter the size of the matrix, and then start it with the given size? Edit the question, it is not at all clear the problem.
– user28595
Yes, as in http://pastebin.com/vp5sFiXC
– user39783