Answer to Question #60270 in Java | JSP | JSF for Theressa Lalanne

Question #60270
1. In the main method place a method call to the method that will store the returned result in a variable of your choosing. Use number1 and number2 as the parameters.
Inside the main method, output the returned value from the method using the variable in a single println statement
1
Expert's answer
2016-06-06T10:23:02-0400
import java.util.Scanner;
public class Choice {

static int choice;
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int number1 = (int) (Math.random() * 100);
int number2 = (int) (Math.random() * 100);

System.out.print("Make your choice. Choose one number: " + number1 + " " + number2 + "\nYour choice: ");
choice = in.nextByte();
choice = selectionMethod(number1, number2);
System.out.print("You choose the number of: " + choice);
}

private static int selectionMethod(int number1, int number2) {
if (number1 == choice) return number1;
else return number2;
}
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS