analuisavilas Posted February 21, 2014 at 06:33 PM Report #546078 Posted February 21, 2014 at 06:33 PM Boa tarde Como e que se faz uma matriz em java? Eu sei que são precisos 2 ciclos, para as linhas e as colunas.
HappyHippyHippo Posted February 21, 2014 at 06:42 PM Report #546079 Posted February 21, 2014 at 06:42 PM int[][] matrix_de_inteiros_de_10_por_10 = new int[10][10]; IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
analuisavilas Posted February 21, 2014 at 06:50 PM Author Report #546080 Posted February 21, 2014 at 06:50 PM int[][] matrix_de_inteiros_de_10_por_10 = new int[10][10]; da para fazer como uma classe: tipo. public int linha, int coluna ?
HappyHippyHippo Posted February 21, 2014 at 06:57 PM Report #546081 Posted February 21, 2014 at 06:57 PM sim para para criar uma classe de manuseamento da matriz (podes criar o que te bem apetecer), mas para que queres complicar ? IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
analuisavilas Posted February 21, 2014 at 07:02 PM Author Report #546082 Posted February 21, 2014 at 07:02 PM int[][] matrix_de_inteiros_de_10_por_10 = new int[10][10]; tendo a matriz como e que eu percorro a matriz e a preencho ?
HappyHippyHippo Posted February 21, 2014 at 07:34 PM Report #546084 Posted February 21, 2014 at 07:34 PM tendo a matriz como e que eu percorro a matriz e a preencho ? Eu sei que são precisos 2 ciclos, para as linhas e as colunas. IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
analuisavilas Posted February 21, 2014 at 09:10 PM Author Report #546095 Posted February 21, 2014 at 09:10 PM sim para para criar uma classe de manuseamento da matriz (podes criar o que te bem apetecer), mas para que queres complicar ? então como e que percorre a matriz e imprimo os resultados?
HappyHippyHippo Posted February 22, 2014 at 12:12 PM Report #546126 Posted February 22, 2014 at 12:12 PM (edited) então como e que percorre a matriz e imprimo os resultados? estar a responder a isso é fazer o trabalho todo, não é ? fica só um exemplo de uma classe para manusear uma matriz (não é genérica para não complicar): class Matrix { private int width; private int height; private int[][] matrix; public Matrix(int width, int height) { if (width == 0 || height == 0) throw IllegalArgumentException("valor de tamanho inválido de zero"); this.width = width; this.height = height; this.matriz = new int[this.width][this.height]; } public int getWidth() { return this.width; } public int getHeight() { return this.height; } public int getCell(int x, int y) { if (this.x >= this.width || this.y >= this.height) return IndexOutOfBoundsException(); return this.matrix[x][y]; } public int[] row(int y) { if (this.y >= this.height) return IndexOutOfBoundsException(); int[] result = new int[this.width]; for (int i = 0; i < this.width; i++) result[i] = this.matrix[i][y]; return result; } public int[] column(int x) { if (this.x >= this.width) return IndexOutOfBoundsException(); int[] result = new int[this.height]; for (int i = 0; i < this.height; i++) result[i] = this.matrix[x][i]; return result; } } Edited February 22, 2014 at 12:12 PM by HappyHippyHippo IRC : sim, é algo que ainda existe >> #p@p Portugol Plus
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now