re: A Java Question

Try this:
you have
if(condition1) && (condition2
but all conditions should be in () like this:
if vcondition1 && condition2
See if that makes a difference.

Have a great day,
Alex

----- Original Message -----
From: Jared Wright <wright.jaredm@xxxxxxxxx
To: programmingblind@xxxxxxxxxxxxx
Date sent: Tue, 29 Jan 2008 22:44:12 -0500
Subject: A Java Question

Hi all, Well, I think this is going to end up real silly, but my
head
hurts and I've combed through this code who knows how many times.
So I
bring the quandary to you... Code, with contextual comments, is
below.
Per the subject, we're dealin' in Java.

public static void gradesort(int scores[]) { // The scores array
consists of exam scores, ranging from 1 to 100. Its size and
values were
established in another method. This method's job is to sort the
scores
into letter grades using the typical 100-90-80-70-60 scale and
print the
output.
   int[] grades = {0, 0, 0, 0, 0, 0}; // Set up an array to hold
counters for each of the letter grades A, B, C, D, and F.
initialize
them all to 0.
for (int i=0; i<scores.length; i++) { // This loops through
all the
scores in the "Scores" array.
       if (scores[i] <= 100) && (scores[i] > 90)
grades[0]++; // Check to see if the given score is
between
90 and 100, and increment the counter for A if it is.
       if (scores[i] <= 90) && (scores[i] > 80)
grades[1]++; // Same thing, just incrementing the B
counter
this time.
       if (scores[i] <= 80) && (scores[i] > 70)
           grades[2]++; // etc.
       if (scores[i] <= 70) && (scores[i] > 60)
           grades[3]++;
       if (scores[i] < 60)
grades[5]++; // Note I skipped over grades[4], since
this
would be a counter for E.
       }
for (char letter='A'; letter<='E'; letter++) { // Loop
through the
now completed counters.
       if (letter == 'E') {
letter++; // Fix the discrepancy caused by E. This
is why I
skipped the grades[4] value a few lines above.
           }
       System.out.println("Number of "+letter+"'s:
"+grades[letter-'A']); // Print each letter and the value of its
corresponding counter.
       }
   }



The fun comes with the if statements.  All get "Illegal start of
expression" and "expected ;" errors at compile. I thought it
might be
wanting {}'s for the if statements, (I remembered in some other
languages if a conditional statement's innards are all on one
line,
then you can exclude the braces and wasn't sure about Java). But
I put
them in and got the same errors. AS you can see, I've since
removed them
again. But I'm not seeing what's wrong here. A nudge in the
right
direction will really make my evening! Thanks in advance.

Jared
__________
View the list's information and change your settings at
http://www.freelists.org/list/programmingblind


__________
View the list's information and change your settings at http://www.freelists.org/list/programmingblind

Other related posts: