Re: A Java Question

  • From: "black ares" <matematicianu2003@xxxxxxxxxxx>
  • To: <programmingblind@xxxxxxxxxxxxx>
  • Date: Wed, 30 Jan 2008 13:03:06 +0200

how i know in java 1.4 which is the last I worked in before moving to dotnet
the follwoing lines are equivalent:
int scores[]=new int[3]
int[] scores=new int[3];

----- Original Message ----- From: "Sina Bahram" <sbahram@xxxxxxxxx>
To: <programmingblind@xxxxxxxxxxxxx>
Sent: Wednesday, January 30, 2008 6:32 AM
Subject: RE: A Java Question

You have the array syntax wrong in your parameter  to the function, the
brackets are in the wrong position, and you have it the right way further
down in your method.

Take care,

-----Original Message-----
From: programmingblind-bounce@xxxxxxxxxxxxx
[mailto:programmingblind-bounce@xxxxxxxxxxxxx] On Behalf Of Jared Wright
Sent: Tuesday, January 29, 2008 10:44 PM
To: programmingblind@xxxxxxxxxxxxx
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
       if (scores[i] <= 80) && (scores[i] > 70)
           grades[2]++; // etc.
       if (scores[i] <= 70) && (scores[i] > 60)
       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

View the list's information and change your settings at

View the list's information and change your settings at

View the list's information and change your settings at

Other related posts: