Login | Iscriviti | FAQ
Anonymous

java lesson 4.3 'sorting arrays' ...

+ Rispondi al messaggio

2 messaggi Pagina 1 di 1


java lesson 4.3 'sorting arrays' ...

da vinz2112ruzz » lun giu 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 utente

vinz2112ruzz

  • Messaggi: 1
  • Iscritto il: lun giu 15, 2015 4:24 pm

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

da Griggs1024 » gio giu 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 utente

Griggs1024

  • Messaggi: 1
  • Iscritto il: gio giu 25, 2015 11:23 am


+ Rispondi al messaggio

Pagina 1 di 1