i having trouble figuring out how prompt question allows user enter number or character start or end loop.
the following code
import java.util.scanner; public class diceroller{ public static void main(string[] args){ scanner keyboard = new scanner(system.in); int score; int sum=0; int roll1 = genraninrange(1, 6); int roll2 = genraninrange(1, 6); int roll3 = genraninrange(1, 6); system.out.println("your rolls were: " + " " + roll1 + " " + roll2 + " " + roll3); if (roll1 == roll2 || roll2 == roll3 || roll1 == roll3){ // start of first loop system.out.println("you had 2 matching rolls! gain 50 points."); score = 50; sum += score; if (roll1 == roll2 && roll2 == roll3 && roll1 == roll3){ // nested loop int rollsum = roll1 + roll2 + roll3; if (rollsum == 18){ // nested loop 2 system.out.println("you had 3 matching 6's! gain 500 points."); score = 500; sum += score; } // end nested loop 2 } // end nested loop } // end of first loop else { system.out.println("sorry, had 0 matching die."); score = 1; sum -= score; } system.out.println("your score was: " + sum); if (sum > 0){ system.out.println("would continue?"); } else{ system.out.println("you out of points. restart?"); } } // end main public static int genraninrange(int start, int end) { return (int)(math.random()*(end-start+1.0)) + start; } // end genraninrange } // end dice roller
this should trick
system.out.print("would continue? y/n: "); string userresp = scanner.nextline(); put rest of code in while loop. , have there boolean defined @ beginning true first loop, , compare userresp y or n set boolean.
Comments
Post a Comment