Sou inciante e não entendo porque esse código não funcion

5 respostas
C
class PassByReference{

int onetoZero(int arg[]){

int count=0;
for(int i=0; i< arg.length; i++){
		if(arg[i]==1){
			count++;
			arg[i]=0;
		}
	}
	return count;
	}
}

public static void main (String arg[])
	int arr[]= { 1,3,4,5,1,1,7};
	PassByReference test = new PassByReference();
	int numOnes;

	System.out.print(?Values of the array: [?);
	for( int i=0; i < arr.length; i++){
		System.out.print(arr[i] + ? ?);
	}
	System.out.println(?]?);
	
	numOnes= test.onetoZero(arr);
	System.out.println(?Number of Ones = ? + numOnes);
	System.out.print(?New values of the array: [ ?);
	for( int i=0; i < arr.length; i++){
		System.out.print(arr[i] + ? ?);
	}
	System.out.println(?]?);

}

5 Respostas

M

ninguém aqui sabe nem oq teu código deveria ta fazendo pra poder ajudar. :???:

R

O problema apenas está em um parênteses colocado em lugar errado e um faltando. Abaixo indico com comentário em maiúsculo.

E
Veja se roda, tinha chaves sobrando no início e faltando no final:

public class PassByReference{

int onetoZero(int arg[]){

int count=0;
for(int i=0; i< arg.length; i++){
		if(arg[i]==1){
			count++;
			arg[i]=0;
		}
	}
	return count;
}


public static void main (String []args){
	int arr[]= { 1,3,4,5,1,1,7};
	PassByReference test = new PassByReference();
	int numOnes;

	System.out.print("Values of the array: [");
	for( int i=0; i < arr.length; i++){
		System.out.print(arr[i] + " ");	
		System.out.println("]");
		numOnes= test.onetoZero(arr);
		System.out.println("Number of Ones = " + numOnes);
		System.out.print("New values of the array: [ ");
		for( int j = 0; j < arr.length; j++){
			System.out.print(arr[j] + "");
		}
		System.out.println("]");
	}
}

}

Qualquer coisa, é só falar

E

Também tinha um problemas com as aspas que o meu ide eclipse não reconheceu, pareciam estar em itálico, não foi problema de ctrl C, deu o mesmo problema no JDeveloper…
Valeu

R

Pessoal, desculpem, eu havia dito parênteses mas o certo era chaves, como eliselbert colocou.

Vlw

Criado 21 de março de 2005
Ultima resposta 21 de mar. de 2005
Respostas 5
Participantes 4