re: A Java Question
- From: Alex Hall <mehgcap@xxxxxxx>
- To: programmingblind@xxxxxxxxxxxxx
- Date: Tue, 29 Jan 2008 23:33:01 -0500
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:
- » A Java Question
- » re: A Java Question
- » RE: A Java Question
- » Re: A Java Question
----- 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
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
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.
them all to 0.for (int i=0; i<scores.length; i++) { // This loops through
scores in the "Scores" array.
if (scores[i] <= 100) && (scores[i] > 90)
grades[0]++; // Check to see if the given score is
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
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
would be a counter for E.
}
for (char letter='A'; letter<='E'; letter++) { // Loop
now completed counters.
if (letter == 'E') {
letter++; // Fix the discrepancy caused by E. This
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 ofexpression" and "expected ;" errors at compile. I thought it
wanting {}'s for the if statements, (I remembered in some other
languages if a conditional statement's innards are all on one
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