Poxa eu n to conseguindo achar o erro nesse ARRAY, alguem pode me ajudar? Preciso entregar isso segunda… me dão umas dicas da onde ta meu erro pessoal…
/*
* Criado em 19/03/2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - JAVA - Code Style - Code Templates
*/
/**
* @author Eduardo Bregaida
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - JAVA - Code Style - Code Templates
*/
package algebra;
import java.io.*;
import java.lang.*;
public class algebra {
public static void main(String[] args) throws IOException {
int[] z = null; //Array
//Lê G
System.out.println ("Digite a quantidade de G: ");
InputStreamReader isr = new
InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
String s = br.readLine();
int g = Integer.parseInt(s);
int cont;
while (g>=2||g<=6){
for (cont=0;cont<g;cont++){
System.out.print("Digite os Números de G: ");
s = br.readLine();
z=new int[cont];
}
//Lê Elevado
System.out.print("Digite o número de N: ");
s = br.readLine();
int n = Integer.parseInt(s);
while (n>=2||n<=6){
if (n==2){
int x,y;
for (x=0;x<g;x++){
for (y=0;y<g;y++){
System.out.println("(" +z[x]+","+z[y]+")");
}
}
}
return;
}
}
}
}
Erro:
Digite a quantidade de G:
2
Digite os Números de G: 1
Digite os Números de G: 2
Digite o número de N: 2
(0,0)
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 1
at algebra.algebra.main(algebra.java:71)
O Certo Seria:
Mostrar na tela ao invés dakela exception mostrar:
(1,1),(1,2),(2,1),(2,2)>
>