Another array issue

I keep getting <identifier> expected when I try to compile the program below. Not sure what I've missed.

import java.io.*;

import java.util.*;

publicclass TestScores{

staticfinalint MAX_SCORE = 200;

staticfinalint CATEGORY_DIFFERENCE = 25;

publicstaticvoid main(String[] args)throws FileNotFoundException{

int[] categories =newint[MAX_SCORE/CATEGORY_DIFFERENCE];

Scanner inFile =new Scanner(new FileReader("testscores.txt"));

while(inFile.hasNext()){

int score = inFile.nextInt();

categories[(score==MAX_SCORE)?categories.length-1:score/CATEGORY_DIFFERENCE]++;

}

inFile.close();

for(int i=0,int min=0;i<categories.length-1;i++){

System.out.printf("Scores between [%d, %d] = %d%n",min,(min+=CATEGORY_DIFFERENCE)-1,categories[i]);

}

System.out.printf("Scores between [%d, %d] = %d%n",MAX_SCORE-CATEGORY_DIFFERENCE,MAX_SCORE,categories[categories.length-1]);

}

}

>

[2090 byte] By [mattvgta] at [2007-11-27 11:01:15]
# 1

> for(int i=0,int min=0;i<categories.length-1;i++){

should be:

for(int i = 0, min = 0; i >< categories.length - 1; i++){

(Notice there's a bug in the forum software to print a less-than as a greater-thanless-than.)

hiwaa at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 2

How many time need it be said?

When you get an error, include the EXACT error message DO NOT paraphrase. The error message will also give you a line number. Please indicate the line of code. We do not want to count, especially if the code is several hundred lines of code long and/or your post does not include all the code.

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 3

Still get <identifier> expected when I try to compile it.

mattvgta at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 4

FFS!

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 5

Do you go to the doctor and say "I'm sick" and expect him to cure you?

DETAILS!

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 6

Z:\java\TestScores.java:18: <identifier> expected

for(int i=0,min=0,int i>categories.length-1, int i++){

^

Z:\java\TestScores.java:22: illegal start of expression

}

^

Z:\java\TestScores.java:21: ';' expected

System.out.printf("Scores between [%d, %d] = %d%n",MAX_SCORE-CATEGORY_DIFFERENCE,MAX_SCORE,categories[categories.length-1]);

^

3 errors

Sorry, I was using BlueJ and it doesn't give full errors.

mattvgta at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 7

Compilers are smart. Once you have told them what type a variable is, you do not have to keep reminding them.

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 8

for(int i=0,min=0,int i>categories.length-1, int i++){

BTW the above code is different to the code in your first post. You really do expect us to read your mind.

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 9

Don't use a worsened code. Use your initial code and apply reply #1.

hiwaa at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 10

With reply one suggestion applied, I still get:

Z:\java\TestScores.java:18: <identifier> expected

for(int i=0,min=0,int i>categories.length - 1, int i++){

^

Z:\java\TestScores.java:22: illegal start of expression

}

^

Z:\java\TestScores.java:21: ';' expected

System.out.printf("Scores between [%d, %d] = %d%n",MAX_SCORE-CATEGORY_DIFFERENCE,MAX_SCORE,categories[categories.length-1]);

^

3 errors

mattvgta at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 11

>Sorry, I was using BlueJ and it doesn't give full errors.

For beginners, use the console.

qUesT_foR_knOwLeDgea at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 12

FFS. Tell me what is wrong with this code.

String s = "Hello";

System.out.println(String s);

floundera at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 13

> With reply one suggestion applied, I still get:

>

> Z:\java\TestScores.java:18: <identifier> expected

> for(int i=0,min=0,int

> i>categories.length - 1, int i++){

> ^

> al start of expression

> }

>^

> \TestScores.java:21: ';' expected

> System.out.printf("Scores between

> [%d, %d] =

> %d%n",MAX_SCORE-CATEGORY_DIFFERENCE,MAX_SCORE,categor

> es[categories.length-1]);

>

>

> 3 errors

It's clearly telling you what to do. Read the error message. It says ; expected. Where do you think in that for statement you would need to use ' ; ' ?Now make the necessary changes.

qUesT_foR_knOwLeDgea at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 14

You need this

http://java.sun.com/docs/books/tutorial/

qUesT_foR_knOwLeDgea at 2007-7-29 12:35:29 > top of Java-index,Java Essentials,Java Programming...
# 15

System.out.println(s);

FFS. Tell me what is wrong with this code.

String s = "Hello";

System.out.println(String s);

mattvgta at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 16

> With reply one suggestion applied, I still get:

>

> Z:\java\TestScores.java:18: <identifier> expected

> for(int i=0,min=0,int

> i>categories.length - 1, int i++){

> ^

> al start of expression

> }

>^

> \TestScores.java:21: ';' expected

> System.out.printf("Scores between

> [%d, %d] =

> %d%n",MAX_SCORE-CATEGORY_DIFFERENCE,MAX_SCORE,categor

> es[categories.length-1]);

>

>

> 3 errors

You still use the worsened version of the code. I have said don't use it.

hiwaa at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 17

and? You cannot apply the same logic and determine what is wrong with your code?

floundera at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 18

hiwa I used what you said in reply 1.

mattvgta at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 19

> hiwa I used what you said in reply 1.

And at the same time you didn't use the code you have posted in your main reply.

qUesT_foR_knOwLeDgea at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 20

Remove the fucking int from in front of the fucking i. Is that plain enough for you?

BTW the i in the conditional and incremental statements not the initialisation statement. Do you understand what that means?

floundera at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 21

Doh! Sorry for aggrevation. I've been doing this for too long tonight. It is working now. Thanks.

mattvgta at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 22

Yes I understand. I've been doing this for 4 weeks, gimme a break. ****.

mattvgta at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 23

We did give you a break but it still took 20 replies for you to understand your mistake. The human brain has several billion neurons (or brain cells) and it is expected that you use ony a few of them and think for yourself.

floundera at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 24

Oh and before you get all offended and make some reply, I saw this quote recently:

Little minds are wounded by the smallest things

floundera at 2007-7-29 12:35:34 > top of Java-index,Java Essentials,Java Programming...
# 25

Yeah..... anyways, thanks for the help. I do appreciate it.

mattvgta at 2007-7-29 12:35:35 > top of Java-index,Java Essentials,Java Programming...