Flowchart: What is the look of this flowchart when finished?
- What does the program for that flowchart do? Write the full program.
- What is a pseudorandom number? What is the code to generate a random number?
- In the Gambler’s ruin, when does the user exit the program?
- In the Gambler’s ruin, how many while-loops are needed? Explain.
- How do you use a while structure to print the integers from 34 through 41 inclusive?
- How do you add all the integers from 34 through 41 inclusive? Show code.
- Write the code to prompt the user for an integer N. Your program will display a square pattern of asterisks N by N
- Write the code to print all even integers from 36 through 12 inclusive.
- Write the code for a while loop to prompt the user if he or she wants to continue to input more integers.
- The following questions are related to this flowchart:
a. What is the oval shape used for?
b. What is the code for each instruction in the flowchart?
c. Draw the flowchart to find the two digits in the middle of a 4-digit integer.
Write the code to calculate and display the following output:
“ 1 1” “ 2 4” “ 3 9” “ 4 16” “ 5 25”
Mystery: What does this program do?
for ( int i =1; i < 21 ; i++) { System.out.printf( "%10d" ,(int)(1 + Math.random( ) * 6)); if ( i % 5 == 0 ) # print newline every 5 rolls System.out.println(); }
Simulation: What does this program do? How would you finish it up?
int frequency1 = 0 int frequency2 = 0 int frequency3 = 0 int frequency4 = 0 int frequency5 = 0 int frequency6 = 0 for ( int i =1; i < 6001 ; i++) // 6000 die rolls { face = (int)(1 + Math.random( ) * 6); if (face == 1) frequency1 += 1 // frequency counted else if ( face == 2 ) ... ... }
Loop 1: What structure can be used to repeat a block of statements when the termination of the loop is not known? Explain your answer.
Loop 2: What structure can be used to repeat a block of statements when the termination of the loop is known? Explain your answer.