这是我的代码
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;
...
在重要的事情之后,我切断了代码的结尾。我在" temp = scan.nextChar();"的行上收到错误。说没有找到符号。我的错误是什么?
答案 0 :(得分:2)
Scanner
没有nextChar
方法,您可以使用next
来将字符设为String
。
String charInput = scan.next();
char character = charInput.charAt(0);
答案 1 :(得分:0)
没有Scanner#nextChar()
方法。相反,您可以temp = scan.next().charAt(0);
答案 2 :(得分:0)
您无法在扫描仪中找到nextChar()。使用next()或nextLine()