Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to find all the four-digit numbers that have this property. For

ID: 3542690 • Letter: W

Question

                    Write a program to find all the four-digit numbers that have this property.                 

                    For example, here's a number that fails the test: 1430. Add 14 to 30 to get 44, square 44 to get 1936, but this is not what we started with (i.e. 1430) so this                    number fails the test.                 

                    Write a program that outputs the probability of winning at the game of craps. The rules for the game of craps are:                 

                        A player rolls two dice. Each die has six faces. These faces contain 1, 2, 3, 4, 5 and 6 spots. After the dice have come to rest, the sum of the spots on                        the two upward faces is calculated. If the sum is 7 or 11 on the first throw, the player wins. If the sum is 2, 3 or 12 on the first throw (called                        "craps"), the player loses (i.e. the "house" wins). If the sum is 4, 5, 6, 8, 9 or 10 on the first throw, then that sum becomes the player's "point". To                        win, you must continue rolling the dice until you "make your point". The player loses by rolling a 7 before making the point.

Explanation / Answer

public class Craps {


public static int NUM_GAMES = 10000;



public static void main(String[] args) {


int numWins = 0;


int numLosses = 0;


int x=(int)(Math.random()*6);


int y=(int)(Math.random()*6);


for (int i = 0; i<=10000; i++)


if ((x+y) == 7 || (x+y) == 11)


numWins = numWins +1;


else if ((x+y)==2 || (x+y)==3 || (x+y)==12)


numLosses = numLosses + 1;


else if ((x+y) == 4 || (x+y) == 5||(x+y) == 6||(x+y)==8||(x+y)==9||(x+y)==10)


int xone=(int)(Math.random()*6), int yone=(int)(Math.random()*6);


{


if (xone+yone)==(x+y)


numWins = numWins+1;


else numLosses=numLosses+1;


}


// Output probability of winning


System.out.println("In the simulation, we won " + numWins +


" times and lost " + numLosses + " times, ");


System.out.println("for a probability of " +


(double)(numWins)/(double)(numWins + numLosses));


}


}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote