Ragazzo Posted April 13, 2009 at 10:29 AM Report #256502 Posted April 13, 2009 at 10:29 AM Boas pessoal. O meu nome é Fábio frequento o curso de Ciencias dos Computadores na FCUP, foi-me proposto um trabalho para entregar ate dia 14 em java, que é fazer o jogo da vida(Game of Life) maior parte dos programadores deve conhece-lo, eu sou um iniciado em java pois so este semestre é que lidei pela primeira vez com Java, de modos que tenho algumas dificuldades, agora deparei-me com uns erros que por mais que tente nao consigo corrigi-los gostava que me pudesse dizer qual o problema do meu programa ou que me pudessem corrigir se for possivel. vou colar aqui o codigo. De momento tenho 12 erros ja tive mais, mas nao consigo mesmo corrigir estes, nao percebo porque é que nao me aceita as expressoes. Tentem compilar o ficheiro e digam-me alguma coisa se possivel. Obrigado import java.util.*; class Life { public static void main(String [] args) { Scanner stdin = new Scanner(System.in); int L = stdin.nextInt(); int C = stdin.nextInt(); int I = stdin.nextInt(); int[][] matriz; int[][] matriz = new int[L][C]; void inicializa() { int i,j; for (i=1;i<L-1;i++) for (j=1;j<C-1;j++) matriz [i][j] = (int) (Math.random() * 1.5); } void imprimeTabuleiro() { int i,j; for (i=0;i<L;i++) { for(j=0;j<C;j++) if (matriz[i][j]==1) System.out.print('O'); else System.out.print('.'); System.out.println(); } System.out.println(); } int vizinhos(int i,int j) { return matriz[i-1][j-1]+matriz[i-1][j]+matriz[i-1][j+1]+matriz[i][j-1]+matriz[i][j]+matriz[i][j+1]+matriz[i+1][j-1]+matriz[i+1][j]+matriz[i+1][j+1]; } int [][] iteracao() { int [][] aux = new int[L][C]; int i,j; for (i=1;i<L-1;i++) for (j=1;j<C-1;j++) { if (matriz[i][j]==1){ if ((vizinhos(i,j)<2) || (vizinhos(i,j)>3)) aux[i][j]=0; else aux[i][j]=1; } else { if (vizinhos(i,j)==3) aux[i][j]=1; else aux[i][j]=0; } } return aux; } void simulaVida(int I) { int i; for(i=0;i<I;i++) { imprimeTabuleiro(); matriz=iteracao(); } } } }
André Sousa Posted April 13, 2009 at 12:53 PM Report #256513 Posted April 13, 2009 at 12:53 PM Sinceramente, acho que deves dar uma vista de olhos nos apontamentos teóricos, exercitar um pouco e voltar a pegar neste trabalho. Cometes alguns erros básicos que demonstram muita falta de estudo.
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