Results 1 to 4 of 4
  1. #1
    supernowlin is offline Member
    Join Date
    Oct 2013
    Posts
    3
    Rep Power
    0

    Default Really need some help on school

    This is the question and what I have so far. I would love some help for this one.


    Design and implement an application that reads an arbitrary number of integers that are in the range 0 to 50 inclusive and counts how many occurrences of each are entered. Stop reading input when any integer outside the range 0 to 50 is encountered. After all input has been processed, print all of the values (with the number of occurrences) that were entered one or more times.
    Prompt for input with System.out .print("enter numbers: ").
    The output should be one frequency count per line. For example:
    enter numbers: 2 2 5 5 5 5 5 5 2 5 -1
    3 occurrences of 2
    7 occurrences of 5
    SPECIFICATION OF NAMES: Please name your application class Frequency



    //Samuel Tate
    //Itec 120
    //Frequnency
    // Will not complile

    import java.util.Scanner;

    public class Frequency {

    public static void main (String[] args) {


    int input = 0;
    int[] integers = new int[51];
    Scanner scan = new Scanner(System.in);


    while(input != 51); {

    System.out.print("Enter an arbitrary number of integers in the range 0-50 (enter 51 to exit) : ");
    input = scan.nextInt();
    if(input == 51) break;
    if(input < 0 || input > 50){
    System.out.println("number out of range");
    }
    integers[input]++;
    continue;

    }

    for(int index = 0; index < 51; index++);
    if(integers[index] > 0)
    System.out.println(index + ": " + integers[index]);


    }


    }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Really need some help on school

    Well, for one thing your while loop has a dangling semicolon after it. You need to remove it. Same for you for loop at the end. I am not certain about
    what you are trying to accomplish with the termination logic. Does an input value of 51 cause the loop to exit? And the continue statement at the
    end of the while loop is unnecessary.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

  3. #3
    Junky's Avatar
    Junky is offline Grand Poobah
    Join Date
    Jan 2011
    Location
    Dystopia
    Posts
    3,782
    Rep Power
    7

    Default Re: Really need some help on school

    The exact same advice offered in duplicate post

    another school homework thread

  4. #4
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,501
    Rep Power
    5

    Default Re: Really need some help on school

    Another waste of my time. Maybe this time the advice will sink in.

    Regards,
    Jim
    The Java™ Tutorial | SSCCE | Java Naming Conventions
    Poor planning our your part does not constitute an emergency on my part.

Similar Threads

  1. Need some help for a school project.
    By Jaxful in forum New To Java
    Replies: 4
    Last Post: 10-19-2013, 10:42 PM
  2. Need help with school project
    By camaro01 in forum New To Java
    Replies: 16
    Last Post: 02-20-2011, 06:34 PM
  3. School project help!
    By Addez in forum Advanced Java
    Replies: 5
    Last Post: 09-17-2010, 10:37 PM
  4. Need help with school project!
    By jaxxx in forum New To Java
    Replies: 5
    Last Post: 03-25-2010, 08:55 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •