Hey guys,
I think I have this mostly figured out but i'm still getting some errors, I'm not sure if it's a syntax thing or if I called out a variable wrong.
For some reason eclipse is saying that my variable [B]average[/B] "may not have locally been declared" which doesn't make sense to me, because it is, or so I think. If you could take a look and give me an idea of what is cause this I would really appreciate it!

import java.util.Random;

public class lab11a_killackey {
public static void main(String args[])
{

    Random randomNumbers = new Random();
    int a[]= new int [ 1000 ];
    a [1000] = 1 + randomNumbers.nextInt( 51 );

    int big = -1;
    int small = 52;
    int n;

    for (int i=0; i<1000; i++)
    {
        if (a[i]> big)
            big = a[i];
    }
    for (int i=0; i<1000; i++)
    {
        if (a[i] < small )
            small = a[i];
    }
    int average;
    for (int i= 0; i<1000; i++)
        [B]average[/B] += (a[i])/1000;


    int ans;
    ans= countItems(a, [B]average[/B]);
    int ansb;
    ansb = countItemsb(a, [B]average[/B]);

    System.out.printf("The largest of the 1000 integers is: %d", big);
    System.out.printf("The smallest of the 1000 integers is: %d", small);
    System.out.printf("The[B] average[/B] of the 1000 integers is: %d", average);
    System.out.printf("The number of integers below average is: %d", ansb);
    System.out.printf("The number of integers above average is: %d",ans);

}


public static int countItems( int a [],  int average)
{
    int cnt = 0;
    for (int i= 0; i<1000; i++)
        if (a[i] > average)
            cnt ++;
    return cnt;
}
public static int countItemsb(int a[], int average)
{   
    int cntb = 0;
    for (int i=0; i<1000; i++)
        if(a[i] < average)
            cntb++;
    return cntb;

}
}

Edited 3 Years Ago by mike_2000_17: Fixed formatting

Code tags and formatting please.

import java.util.Random;

public class lab11a_killackey {
public static void main(String args[])
{

Random randomNumbers = new Random();
int a[]= new int [ 1000 ];
a [1000] = 1 + randomNumbers.nextInt( 51 );

int big = -1;
int small = 52;
int n;

for (int i=0; i<1000; i++)
{
if (a[i]> big)
big = a[i];
}
for (int i=0; i<1000; i++)
{
if (a[i] < small )
small = a[i];
}
int average;
for (int i= 0; i<1000; i++)
average += (a[i])/1000;


int ans;
ans= countItems(a, average);
int ansb;
ansb = countItemsb(a, average);

System.out.printf("The largest of the 1000 integers is: %d", big);
System.out.printf("The smallest of the 1000 integers is: %d", small);
System.out.printf("The average of the 1000 integers is: %d", average);
System.out.printf("The number of integers below average is: %d", ansb);
System.out.printf("The number of integers above average is: %d",ans);

}


public static int countItems( int a [], int average)
{
int cnt = 0;
for (int i= 0; i<1000; i++)
if (a[i] > average)
cnt ++;
return cnt;
}
public static int countItemsb(int a[], int average)
{
int cntb = 0;
for (int i=0; i<1000; i++)
if(a[i] < average)
cntb++;
return cntb;

}
} 

I don't get that error. I get this error:

lab11a_killackey.java:27: variable average might not have been initialized

lab11a_killackey.java:31: variable average might not have been initialized

You never initialize the variable on line 25.

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This question has already been answered. Start a new discussion instead.