Hi All,
I am getting the follwoing error
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 0
at Chp8Assign1.mai n(Chp8Assign1.j ava:37)
Press any key to continue...
In this program...
public class Chp8Assign1 {
public static void main (String args [ ] )
{
int myArray [ ] = new int [ args.length ]; // for loop to convert String args array to integer myArray
int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;
for (int a = 0; a < args.length ; a++)
{
myArray [a ] = Integer.parseIn t (args [ a ] );
if(myArray [a] >= 90)
{
gradeA++;
}
else if(myArray [a] >= 80 && myArray [a] <= 89)
{
gradeB++;
}
else if(myArray [a] >= 70 && myArray [a] <= 79)
{
gradeC++;
}
else if(myArray [a] >= 60 && myArray [a] <= 69)
{
gradeD++;
}
else if( myArray [a] <= 60)
{
gradeF++;
}
}
int sum = 0;
int largest = myArray[0];
int smallest = myArray[0];
// for loop to find sum, largest and smallest
for (int i = 0; i<myArray.lengt h; i++ )
{
sum = sum + myArray [i]; if ( myArray [ i ] > largest )
largest = myArray [ i ]; if ( myArray [ i ] < smallest ) smallest = myArray [ i ];
}
System.out.prin tln("The sum is " + sum);
System.out.prin tln("The average is " + sum/myArray.length) ;
System.out.prin tln("The largest number is " + largest);
System.out.prin tln("The smallest number is " + smallest);
System.out.prin tln("The number of students with scores of 90-100 (A) is " + gradeA);
System.out.prin tln("The number of students with scores of 80-89 (B) is " + gradeB);
System.out.prin tln("The number of students with scores of 70-79 (C) is " + gradeC);
System.out.prin tln("The number of students with scores of 60-69 (D) is " + gradeD);
System.out.prin tln("The number of students with scores below 60 (F) is " + gradeF);
} // ends main
}
Could anyone point me in the right direction?
Thanks.
I am getting the follwoing error
Exception in thread "main" java.lang.Array IndexOutOfBound sException: 0
at Chp8Assign1.mai n(Chp8Assign1.j ava:37)
Press any key to continue...
In this program...
public class Chp8Assign1 {
public static void main (String args [ ] )
{
int myArray [ ] = new int [ args.length ]; // for loop to convert String args array to integer myArray
int gradeA = 0, gradeB = 0, gradeC = 0, gradeD = 0, gradeF = 0;
for (int a = 0; a < args.length ; a++)
{
myArray [a ] = Integer.parseIn t (args [ a ] );
if(myArray [a] >= 90)
{
gradeA++;
}
else if(myArray [a] >= 80 && myArray [a] <= 89)
{
gradeB++;
}
else if(myArray [a] >= 70 && myArray [a] <= 79)
{
gradeC++;
}
else if(myArray [a] >= 60 && myArray [a] <= 69)
{
gradeD++;
}
else if( myArray [a] <= 60)
{
gradeF++;
}
}
int sum = 0;
int largest = myArray[0];
int smallest = myArray[0];
// for loop to find sum, largest and smallest
for (int i = 0; i<myArray.lengt h; i++ )
{
sum = sum + myArray [i]; if ( myArray [ i ] > largest )
largest = myArray [ i ]; if ( myArray [ i ] < smallest ) smallest = myArray [ i ];
}
System.out.prin tln("The sum is " + sum);
System.out.prin tln("The average is " + sum/myArray.length) ;
System.out.prin tln("The largest number is " + largest);
System.out.prin tln("The smallest number is " + smallest);
System.out.prin tln("The number of students with scores of 90-100 (A) is " + gradeA);
System.out.prin tln("The number of students with scores of 80-89 (B) is " + gradeB);
System.out.prin tln("The number of students with scores of 70-79 (C) is " + gradeC);
System.out.prin tln("The number of students with scores of 60-69 (D) is " + gradeD);
System.out.prin tln("The number of students with scores below 60 (F) is " + gradeF);
} // ends main
}
Could anyone point me in the right direction?
Thanks.
Comment