Está Difícil entender Java

5 respostas
_

E olha que eu sei programar em C, mas tá difícil entender os problemas que acontecem no Java
Por exemplo, este código que não funciona:

class RangeClass

{

int[] makeRange(int lower, int upper)

{

int arr[] = new int[(upper - lower) + 1];
for	(int i = o; i < arr.length; i++)
     arr[i] = lower++;
return arr;     
}
public static void main(String arg[])
{
	int theArray[];
	RangeClass theRange = new RangeClass();
	
	theArray = theRange.makeRange(1,10);
	System.out.print("The array: [ ");
	for(int i = 0; i < theArray.length; i++)
	    System.out.print(theArray[i] + "");
	    
	System.out.println("]")    		
}

}

Alguém pode me dar uma luz?

5 Respostas

R

2 coisas !!!

no último ...

System.out.println("]")

falta o ";"

e no ...

for (int i = o; i < arr.length; i++)

o "i" está sendo inciado pela letra "o"
... ai vai o código correto!

class RangeClass{

	int[] makeRange(int lower, int upper){
	int arr[] = new int[(upper - lower) + 1];

	for (int i = 0; i < arr.length; i++)
		arr[i] = lower++;
		return arr;
	}

	public static void main(String arg[]){

		int theArray[];
		RangeClass theRange = new RangeClass();
		theArray = theRange.makeRange(1,10);

		System.out.print("The array: [ ");

		for(int i = 0; i < theArray.length; i++)
			System.out.print(theArray[i] + "");
			System.out.println("]");
	}
}

o resultado é ...

The array: [ [telefone removido]]
C

Um conselho, use uma IDE mesmo que simples. Tem editores muito bons, simples e que te avisam sobre esses erros bestas, mas quando compila o javac avisa qual o erro. Nesse caso ele com certeza te deu o numero da linha e uma sujestão para sanar o erro. Só precisa de mais atenção e paciência. Java hoje é muito facil comparado a alguns anos atraz.

_

Eu uso o JCreator, e o problema no caso não é que está dando erros. Os erros apontados na mensagem acima foi erro de digitação minha mesmo. Quando eu compilo dá o seguinte erro:
Exception in thread “main” java.lang.NoClassDefFoundError: RangeClass

_
"rcmsj":
2 coisas !!!

no último ...

System.out.println("]")

falta o ";"

e no ...

for (int i = o; i < arr.length; i++)

o "i" está sendo inciado pela letra "o"
... ai vai o código correto!

class RangeClass{

	int[] makeRange(int lower, int upper){
	int arr[] = new int[(upper - lower) + 1];

	for (int i = 0; i < arr.length; i++)
		arr[i] = lower++;
		return arr;
	}

	public static void main(String arg[]){

		int theArray[];
		RangeClass theRange = new RangeClass();
		theArray = theRange.makeRange(1,10);

		System.out.print("The array: [ ");

		for(int i = 0; i < theArray.length; i++)
			System.out.print(theArray[i] + "");
			System.out.println("]");
	}
}

o resultado é ...

The array: [ [telefone removido]]

O problema é a mensagem de erro
Exception in thread "main" java.lang.NoClassDefFoundError: RangeClass

Esses outros ai foi erro de digitação mesmo, mas o erro acima persiste

_

Já resolvi obrigado…
É q eu tinha esquecido de recompilar e estava executando direto.
Agora tenho que tentar entender o código. Se alguém puder me ajudar, agradeço.

Criado 25 de abril de 2005
Ultima resposta 26 de abr. de 2005
Respostas 5
Participantes 3