java - Can I make an exception to the counter in a for loop? -
i'm trying make program play rock, paper, scissors computer. however, part of assignment having player choose amount of rounds play computer. if there tie, round not supposed count towards game.
my code looks -- i'm more focused on for
part of program:
int gameplays = 0; (int = 0; < gameplays; i++) { // if, else if, , else statements make game possible. // here example of part of code: if (cpuchoice.equals ("rock")) { if (userchoice.equals ("scissors")) { system.out.println("rock beats scissors, computer wins."); } else if (userchoice.equals ("paper")) { system.out.println("paper beats rock, computer wins."); } else { system.out.println("you both chose rock! it's tie."); } // rest else if cpuchoice.equals "paper" , else. }
how exclude last else
statement when it's tie counter? i've wrestled couple hours , can't find solutions.
instead of for
suggest while
int = 0; while (i < gameplays) { // if, else if, , else statements make game possible. // here example of part of code: if (cpuchoice.equals ("rock")) { if (userchoice.equals ("scissors")) { system.out.println("rock beats scissors, computer wins."); i++; // increment when there result } else if (userchoice.equals ("paper")) { system.out.println("paper beats rock, computer wins."); i++; // increment when there result } else { system.out.println("you both chose rock! it's tie."); // don't increment if no result } // rest else if cpuchoice.equals "paper" , else. }
}
Comments
Post a Comment