hi good evening.
I have a problem upon compiling with my codes.this is for the game rock, paper and scissors..the problem is: Write a program that will allow user to input character: r-rock/ s-scissors/p-paper. and display the remarks...such as when player1=='r' && player2=='R' it will output "DRAW!. Nobody wins". and if (player1=='r' && player2== 's') the output is: "rock covers scissors". . . . and so on and so forth..and then, the program will only stop if the user wants to stop it. like "Do you wish to continue? press Y-yes and N-no.
so here's my code and the problem when i compile it is...,
it will not go back to the 2 round.... wooooooaaah!! please help me figure this out..Thank you and have a nice day!
import java.util.*; public class PaperRockScissors { public static void main (String[]args){ char p1, p2, repeat; Scanner console= new Scanner(System.in); System.out.print("Player1 turn: "); p1= console.next().charAt(0); System.out.print("Player2 turn: "); p2= console.next().charAt(0); do{ if (((p1 == 'r') || (p1== 'R')) && ((p2== 'r') || (p2== 'R'))) System.out.print("DRAW! Nobody wins."); else if (((p1 == 'p') || (p1== 'P')) && ((p2== 'p') || (p2== 'P'))) System.out.print("DRAW! Nobody wins."); else if (((p1 == 's') || (p1== 'S')) && ((p2== 's') || (p2== 'S'))) System.out.print("DRAW! Nobody wins. "); //for scissors else if (((p1 == 's') || (p1== 'S')) && ((p2== 'p') || (p2== 'P'))) System.out.print("Scissors cut the paper. Player1 wins!"); else if (((p1 == 'p') || (p1== 'P')) && ((p2== 's') || (p2== 'S'))) System.out.print("Scissors cut the paper. Player2 wins!"); //for paper else if (((p1 == 'p') || (p1== 'P')) && ((p2== 'r') || (p2== 'R'))) System.out.print("Paper covers rock. Player1 wins!"); else if (((p1 == 'r') || (p1== 'R')) && ((p2== 'p') || (p2== 'P'))) System.out.print("Paper covers rock. Player2 wins!"); //for rock else if (((p1 == 'r') || (p1== 'R')) && ((p2== 's') || (p2== 'S'))) System.out.print("Rock breaks scissors. Player1 wins!"); else if (((p1 == 's') || (p1== 'S')) && ((p2== 'r') || (p2== 'R'))) System.out.print("Rock breaks scissors. Player2 wins!"); //repeat System.out.println("\nDo you wish to continue the game? \n Y-yes N-no: "); repeat= console.next().charAt(0); } while((repeat=='y') || (repeat== 'Y')); } }