Entrar | Registrar | FAQ
Anonymous

java lesson 4.3 'sorting arrays' ...

+ Postar uma resposta

2 Mensagens Página 1 de 1


java lesson 4.3 'sorting arrays' ...

por vinz2112ruzz » Seg Jun 15, 2015 4:30 pm

Hi, can anyone help the code examples must be wrong 'cos they DON'T work. Netbeans says the for loop is illegal, and it is expecting '(' (here's the code) :

package prjarrays;
import java.util.Arrays;
public class ArraysTest {
public static void main(String[] args) {

int[] aryNums;

aryNums = new int[6];

aryNums[0] = 10;
aryNums[1] = 14;
aryNums[2] = 36;
aryNums[3] = 27;
aryNums[4] = 43;
aryNums[5] = 18;

Arrays.sort(aryNums); (notice u don't need [ ]'s after the array name)

int i;

for (i=0; i < aryNums.length; i=++) {
System.out.println("num : " + aryNums[i]);
}

System.exit(0);
}
}

I hope someone can help, up until now all for loops have worked fine, I don't understand why it's "illegal" all of a sudden.

Thanks Vincent
Avatar de usuário

vinz2112ruzz

  • Mensagens: 1
  • Data de registro: Seg Jun 15, 2015 4:24 pm

Re: java lesson 4.3 'sorting arrays' ...

por Griggs1024 » Qui Jun 25, 2015 11:28 am

I believe you can fix this issue by changing the following parts of your code:

for(int i = 0; i<aryNums.length; i++){
System.out.println("num : " + aryNums[i]);
}
Avatar de usuário

Griggs1024

  • Mensagens: 1
  • Data de registro: Qui Jun 25, 2015 11:23 am


+ Postar uma resposta

Página 1 de 1