Results 1 to 5 of 5

Thread: question help

  1. #1
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default question help

    my assignment is asking me to make an application to read a number of integers from a range to 0-50 inclusive and counts how many times each one is entered, and print all the values after it is processed with the number of times its been entered.
    would i need to implement a scanner of some sort.
    im not getting exaclty what im supposed to do :/

  2. #2
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    we are dealing with arrays

  3. #3
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    You will want a Scanner, yes. You will also have an array of some set size (depending on how many integers you want to store), of type Integer. Then you want to check each nextInt from the scanner to see if it is from 0-50. If it is, store it in the array, then increment an index.

    This is about the best I can give you--once we see a solid effort on your part, a code or algorithm or even a concept, we can go from there.

  4. #4
    socboy6579 is offline Member
    Join Date
    Oct 2010
    Posts
    81
    Rep Power
    0

    Default

    the directions of the program is to read integers from 0-50 inclusive and counts how many times each one is entered. After all the input has been processed, print all the vlaues, with the number of each times each was printed.

    i have this so far

    Java Code:
    public class count {
    
    	/**
    	 * @param args
    	 */
    	public static void main(String[] args) {
    		// TODO Auto-generated method stub
    		
    		
    			int[] intArray= new int[]{0,101,9,42,47,50,93};
    			for (intArray =0; intArray <=50; intArray++);
    			System.out.println(count);
    			
    		
    	}
    
    }
    is this correct so far, im not exactly sure how to print the number of times each one was entered

  5. #5
    Zack's Avatar
    Zack is offline Senior Member
    Join Date
    Jun 2010
    Location
    Destiny Islands
    Posts
    692
    Rep Power
    4

    Default

    Alright, there's a few issues with what you've got.

    First, avoid naming your class something like "count". It's not descriptive nor helpful for you or anyone else on your project. If it's your main class (which it is), perhaps something like countArrayAssignment or something (be creative!).

    Next, in the code you've provided, the array is hardcoded. In your program you will want to avoid doing this as the numbers will actually be provided by the user. Have a look at this link, and you can see by the first code example how you will want to declare your array. (Remember to avoid C&P'ing the whole thing in there--realize what each part of the code is for before you use it.) Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)

    Now, your for loop is a bit odd. You've simply created it and it does nothing. Basically, in English, it's saying "set your array to zero (which can't be done), then increment this value (also cannot be done), then do nothing." Instead, you'll want something like this:
    Java Code:
    for (int i = 0; i < intArray.length; i++) {
        // Some new code will go on this line in the future.
    }
    (Here is some information on array lengths and array looping: http://www.vias.org/javacourse/chap10_05.html)

    And finally, when you do the print line statement, you are simply printing the value of your class, which isn't valid nor practical. Instead, you will want to have created a variable called count before your loop starts.

    I think you're starting on the right track though. Once you've cleaned up the above, paste your new code and we'll keep on going.

Similar Threads

  1. Question mark colon operator question
    By orchid in forum Advanced Java
    Replies: 9
    Last Post: 12-19-2010, 08:49 AM
  2. Question!
    By anjogomez in forum Java Applets
    Replies: 2
    Last Post: 02-21-2009, 03:24 AM
  3. question on jsp
    By munigantipraveen in forum JavaServer Pages (JSP) and JSTL
    Replies: 2
    Last Post: 06-30-2008, 02:47 PM
  4. JSP Question
    By maheshkumarjava in forum JavaServer Pages (JSP) and JSTL
    Replies: 1
    Last Post: 03-29-2008, 10:51 AM
  5. a question
    By slytheman in forum Java Servlet
    Replies: 0
    Last Post: 03-12-2008, 04:11 AM

Posting Permissions

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