Homework 3 Solution 2

# Nextint whileguess1 answercheckresponseguessanswer

This preview shows page 1. Sign up to view the full content.

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: "+ side2); System.out.println("Hypotenuse = "+ hypotenuse +"\n"); } }}} }} 3.Multiply.java The program successfully compiles and runs. import java.util.*; public class Multiply { //random number generator Random randomNumbers = new Random(); Scanner input = new Scanner(System.in); int answer; //the correct answer //ask the user to answer multiplication problems public void quiz() { Scanner input = new Scanner(System.in); int guess = 0; //the users guess answer = checkResponse(guess,answer); System.out.println("Enter your answer (­1 to exit): "); guess = input.nextInt(); while(guess != ­1) { answer = checkResponse(guess,answer); System.out.println("Enter your answer (­1 to exit)"); guess = input.nextInt(); }//end while loop }//end quiz method public int createQuestion() { //get two random numbers between 0 and 9 int digit1 = randomNumbers.nextInt(9); int digit2 = randomNumbers.nextInt(9); //write code to multiply the two variables and store them in a variable answer = digit1 * digit2; System.out.printf("\nHow much is %d times %d?\n", digit1, digit2); return answer; }//end method createQuestion public int checkResponse(int guess,int answer) { if(guess != answer) { System.out.println("Wrong. Please try again. "); } else { System.out.println("You...
View Full Document

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern