Reputation: 43
This is my code
import java.util.Scanner;
import java.util.Random;
public class RPS {
public static void main (String[] args){
Scanner scan = new Scanner(System.in);
Random rand = new Random();
int comp=0, user=0;
char temp = ' ';
System.out.println("Enter Q to quit.");
while(user!=4){
comp = rand.nextInt(3);
System.out.print("Enter your choice (R, P, S): ");
temp = scan.nextChar();
if(temp =='R' || temp =='r')
user=1;
if(temp =='P' || temp =='p')
user=2;
if(temp =='S' || temp =='s')
user=3;
else
user=4;
...
I cut off the end of my code after what was important. Im getting an error on the line that says "temp = scan.nextChar();" that says symbol not found. What is my error?
Upvotes: 2
Views: 46
Reputation: 7919
There is no Scanner#nextChar()
method. Instead you can do temp = scan.next().charAt(0);
Upvotes: 0
Reputation: 23012
Scanner
does not have nextChar
method you can use next
instead to get character as a String
.
String charInput = scan.next();
char character = charInput.charAt(0);
Upvotes: 2