Results 1 to 9 of 9
  1. #1
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default hello please help me out

    can anybody help me out with code?
    i want to write java program to calculate the probability that sum of two numbers is divisible by 4 or 6 when two dice thrown

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Okay? And your question is?

  3. #3
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default Re@masjde

    My question is how to write java code to solve this

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    With a text editor?

    IOW, we are not simply going to give you finished code.

    Give it, at least, a try. If/When you run into problems, post your code and a specific question, and we will be glad to help, but we are not a "homework service".

  5. #5
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default Re

    dude i am really stucked with it...
    i dnt know how to approach this problem using java
    i thought this community is to help beginners...

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    So write a method that determines all possibilites (and keeps a count of them), select all those that are divisible by 4 or 6 (and keeps a count of them, use %), then divide the two.

    That is, at least, possibility, which is what you want, I believe, actual probablity also uses how many rolls were made, and how many of those already fit the criteria, but even with those, the principle remains the same.

    Where is the problem?

    Edit: It is to help beginners, not to do their (home)work for them. You will have received descriptions of the algorithm to use, and will have received instructions on, at the least the basics of, Class construction, so write something. If you have a problem we will be gald to help, but we are not going to write for you. That would not help you, regardless of how much you think it might.
    Last edited by masijade; 03-23-2009 at 11:13 AM.

  7. #7
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default

    yep...the sample space for this problem is 36 as there r 2 dice
    so i have to use 2 for loops?

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    If you mean one loop per die with an if statement and two counters inside the second, that is one definate possibility.

  9. #9
    ron87 is offline Member
    Join Date
    Mar 2009
    Posts
    52
    Rep Power
    0

    Default

    see i worked it out

    class Probability
    {

    public void calculate()
    {
    double sampleSpace=36;
    double count=0;
    double probability=0;
    for(int i =1;i<=6;i++)
    {
    for(int j=1;j<=6;j++)
    {
    if((i+j)%4==0 || (i+j)%6==0)
    {
    count++;
    }
    }
    }
    probability=count/sampleSpace;
    System.out.println("Probability is:"+probability);
    }
    public static void main(String args[])
    {
    new Probability().calculate();
    }
    }

Posting Permissions

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