Array question in java?

I had a problem statement that said input any # of #’s and compute the frequency of each number. This was later modified a bit to be grades, and the array was supposed to be out of representing the grades. so far i have this:

public class ArrayandSwitch

{

public static void main(String[] args)

{

int frequency[] = new int[];

int number;

int grade = ;

Scanner scan = new Scanner(System.in);

System.out.println(“How many numbers are you inputing?”);

number = scan.nextInt();

System.out.println(number);

for(int i = ; i < number; i++)

{

System.out.print(“Enter number ” + (i + ) + “: “);

grade = scan.nextInt();

frequency[grade]++;

}

for(int i = ; i < number; i++)

{

System.out.println(grade + “t” + frequency[grade] + “n”);

}

}

}

My problem is that i can’t display the grade and the frequency(number of times it occurs) because all that will be stored in the grade is the last number entered. I could do this if i made another array but my teacher was clear to not do that. I could also do it if i put the message in the first loop where it displays after every entry but thats also not right. I don’t see how this is possible without using another array for the grades. Anyone have any ideas?

Answer
? Favorite Answer

  • You just needed to reform your bottom for loop:

    for(int i = ; i < number; i++)

    {

    System.out.println(grade + “t” + frequency[grade] + “n”);

    }

    Should be :

    for(int i = ; i < frequency.length; i++)

    {

    if(frequency[i] != )

    System.out.println(i + “t” + frequency[i] + “n”);

    }

  • Other Related Questions

    Learning Visual Basic ?

    Answers Favorite AnswerTry using "System.Diagnostics.Process. GetProcessesByName( "iwmp" ).Length > " for your check.

    Microsoft Office word Fast answer needed its urgent?

    Answers Favorite AnswerTry this:http://www.techsupport.com///microsoft-wo...Here is another thread re: the same issue with instructions:http://www.pcreview.co.uk/forums/modification-not-...http://www.techsupport.com///microsoft-wo...http://support.microsoft.com/kb/http://answers.microsoft.com/en-us/office/forum/of...

    See also  How to showcase my portfolio, sell web design services and hosting?
    Can I download a whole city android google maps?

    Answers Favorite Answer:) Yes!!!Interesting question. I wonder why it has blocked in this way especially considering that Google Earth is very detailed and has good maps of Israel.

    What is meant by ROM ? Explain in simple but elaborate terms.What about mobile ROM’s?

    Answers Favorite AnswerHi Diva below is a link that will give a simple answer.http://wiki.answers.com/Q/What_does_ROM_stand_for_...Hope this helps.Source(s): Experience and wiki answers.ROM is Read only memory. i.e data can write only once.There two types of ROM..ROM.PROMThe difference between ROM and PROM.that is ROM is programmed during manufacturing it means data stored by manufacturing company.PROM is blank memory that a user programmable memory.user can store content on PROM.both ROM and PROM are Read only memory Data can write only once.and its not possible to write so many time.Memories of PROM and ROM are Non-volatile in nature. Its that stored informations can retain even power goes off.

    Leave a Comment