Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Dont know where to start on this Java Code using loops!! Help Please

  1. #1
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Dont know where to start on this Java Code using loops!! Help Please

    Write a program to generate 100 random integers
    in the range of 0 and 99999, nd the frequency count of each digit (0, 1, 2, . . . , 9) in these numbers,
    and print a frequency histogram.

    This is what I have so far:
    import java.util.Scanner;
    public class PA6 {

    /**
    * @param args
    */
    public static void main(String[] args) {
    // TODO Auto-generated method stub

    int num;
    int freq1, freq2, freq3, freq4, freq5, freq6, freq7, freq8, freq9;
    int digit;


    num = (int)(Math.random()*99999);

    while (num > 0) {
    digit = num % 10;
    num = num / 10;


    }


    }

    }


  2. #2
    Crazy Cat Lady KevinWorkman's Avatar
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    5,424
    My Mood
    Hungover
    Thanks
    144
    Thanked 636 Times in 540 Posts

    Default Re: Dont know where to start on this Java Code using loops!! Help Please

    And what exactly does that code do? Does it compile? Does it run? What's missing from it?

    Please use the highlight tags when posting code.
    Useful links: How to Ask Questions the Smart Way | Use Code Tags | Java Tutorials
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    Junior Member
    Join Date
    Sep 2012
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    For starters,
    a) use random inside the while loop
    b) have a counter inside while loop increase till 100 and break

Similar Threads

  1. [SOLVED] I dont know how to complete this code?
    By jwb4291 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: November 8th, 2017, 11:11 PM
  2. dunno how to test this code so i dont know if it works help please
    By jonathanfox in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 24th, 2012, 04:43 AM
  3. Replies: 4
    Last Post: July 25th, 2011, 06:12 PM
  4. Missing a line or two of code,b ut dont know what it is.
    By backdown in forum What's Wrong With My Code?
    Replies: 6
    Last Post: January 20th, 2011, 09:13 AM
  5. WHY this code dont work?
    By sibbe in forum Java Theory & Questions
    Replies: 7
    Last Post: December 9th, 2010, 10:47 AM