From main method to subroutine
I wrote my code and it works completely, but I didn't write my own
methods. The point of the assignment is to practice using subroutines and
that's what I have to use. I read about making my own methods--A LOT. But
I still can't wrap my mind around it.
Here's a piece of my code. Can you help me by explaining how I'd make my
own method with it and call it?
public static void main(String[] args) {
//Display welcome message
System.out.println("Welcome to the Math Functions event!");
Scanner keyIn = new Scanner(System.in);
Scanner userInput;
System.out.print("Press the ENTER key to toss the dice.");
keyIn.nextLine();
//roll dice
Random rand = new Random();
int tries = 0;
int sum = 0;
while (sum != 7 && sum != 11) {
// roll the dice once
int roll1 = rand.nextInt(6) + 1;
int roll2 = rand.nextInt(6) + 1;
sum = roll1 + roll2;
System.out.println(roll1 + " + " + roll2 + " = " + sum);
tries++;
}
}
Any help would be greatly appreciated! Thank you!
No comments:
Post a Comment