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 2 of 2

Thread: In Desperate Need Of Help! TEACHER WONT HELP ME

  1. #1
    Junior Member
    Join Date
    May 2020
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Exclamation In Desperate Need Of Help! TEACHER WONT HELP ME

    The computer should randomly select 1 of 4 words: (HEARTS, DIAMONDS, CLUBS, SPADES)
    1000 times.
    Print out the statistics of the percentage of time each word was chosen.


    import java.util.Scanner;
    import java.util.Random;
    public class QuestionFive {
    public static void main(String[] args) {
    int result;
    int hnum =0, cnum, dnum, snum;
    Scanner scan = new Scanner(System.in);

    for (int i = 0; i < 1000; i += 1) {

    // generate a random numbr between 0 - 3
    Random r = new Random();
    result = r.nextInt(4);
    System.out.println(result);

    // if the random number is zero assume it is hearts.
    if (result == 1) {
    System.out.println(i + " You drew Hearts");
    hnum = hnum + 1;
    }
    // else if the random number is 1 assume it is clubs
    else if (result = "CLUBS")
    cnum = cnum + 1;
    else if (result = "DIAMONDS")
    dnum = dnum + 1;
    else if (result = "SPADES")
    snum = snum + 1*/;
    }
    System.out.println("The chances of getting HEARTS is " + (hnum / 1000.00) * 100 + "%");
    System.out.println("The chances of getting CLUBS is " + (cnum / 1000) * 100 + "%");
    System.out.println("The chances of getting DIAMONDS is " + (dnum / 1000) * 100 + "%");
    System.out.println("The chances of getting SPADES is " + (snum / 1000) * 100 + "%")*/;
    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: In Desperate Need Of Help! TEACHER WONT HELP ME

    Do you have any java programming questions about your program?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. [SOLVED] Desperate help needed with class and methods
    By spangledhoagies in forum Object Oriented Programming
    Replies: 12
    Last Post: September 24th, 2014, 12:37 PM
  2. Replies: 4
    Last Post: June 2nd, 2013, 02:25 AM
  3. Desperate Need of help
    By mszyndlar in forum Java Theory & Questions
    Replies: 2
    Last Post: October 18th, 2011, 03:32 AM
  4. programming hw desperate help!
    By midnightdream13 in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 16th, 2011, 07:58 AM
  5. What is wrong with this code, please desperate
    By macnasty in forum What's Wrong With My Code?
    Replies: 1
    Last Post: May 6th, 2010, 10:26 AM

Tags for this Thread