**已关闭。**此问题为not reproducible or was caused by typos。当前不接受答案。
这个问题是由一个错字或一个无法再复制的问题引起的。虽然类似的问题可能是on-topic在这里,但这个问题的解决方式不太可能帮助未来的读者。
3天前关闭。
Improve this question
我在jGrasp上用Java做了一个代码,我试图寻找如何解决它,但我就是不明白。
rockPaperScissor.java:35: error: incompatible types: int cannot be converted to String
case 0:
^
rockPaperScissor.java:38: error: incompatible types: int cannot be converted to String
case 1:
^
rockPaperScissor.java:41: error: incompatible types: int cannot be converted to String
case 2:
^
3 errors
这是我的代码。
import java.util.Scanner;
public class rockPaperScissor
{
public static void main(String [] args)
{
Scanner input = new Scanner (System.in);
int computer = (int)(Math.random() * 3);
System.out.print("rock (1), paper(2), scissor(3): ");
int user = input.nextInt();
System.out.print("the computer is ");
switch (computer)
{
case 0: System.out.print("scissor."); break;
case 1: System.out.print("rock."); break;
case 2: System.out.print("paper.");
}
switch (user)
{
case 0: System.out.print("scissor"); break;
case 1: System.out.print("rock"); break;
case 2: System.out.print("paper");
}
String name = " ";
switch (name)
{
case 1:
name = "scissor";
break;
case 2:
name = "rock";
break;
case 3:
name = "paper";
}
System.out.print("You are " + name );
if (computer == user)
System.out.println("too.It is a draw.");
else
{
boolean win = (user == 0 && computer == 2) ||
(user == 1 && computer == 0)||
(user == 2 && computer == 1);
if (win)
System.out.println(". You won.");
else
System.out.println(". You lose.");
}
}
}
我期待它说
rock(1), paper(2), scissor(3):1
The computer is Scissor. You are rock. you win
rock(1), paper(2), scissor(3):3
The computer is rock. You are scissor. you lose
rock(1), paper(2), scissor(3):2
The computer is paper. You are paper. you draw.
1条答案
按热度按时间9gm1akwq1#
问题就在这里
如果变量'name'是
String
,则使用int
应该是的