java猜拳游戏运行代码错误修改
import java.util.Random; class ShiTouJianDaoBu {
public String chuQuan() {
Random rand = new Random();
int i = rand.nextInt(3);
String str = "";
if (i == 0) {
str = "石头";
}
if (i == 1) {
str = "剪刀";
}
if (i == 2) {
str = "布";
}
return str;
}
}
class CaiPan {
public String caiJue(String str1, String str2) {
String str = "输";
if (str1.equals("石头") && str2.equals("剪刀")) {
str = "赢";
}
if (str1.equals("石头") && str2.equals("布")) {
str = "输";
}
if (str1.equals("石头") && str2.equals("石头")) {
str = "平";
}
if (str1.equals("剪刀") && str2.equals("石头")) {
str = "输";
}
if (str1.equals("剪刀") && str2.equals("布")) {
str = "赢";
}
if (str1.equals("剪刀") && str2.equals("剪刀")) {
str = "平";
}
if (str1.equals("布") && str2.equals("石头")) {
str = "赢";
}
if (str1.equals("布") && str2.equals("剪刀")) {
str = "输";
}
if (str1.equals("布") && str2.equals("布")) {
str = "平";
}
return str;
}
}
public class ShiTouJiandaoBu{
/**
* @param args
*/
public static void main(String[] args) {
CaiPan cp = new CaiPan();
DianNao dn1 = new DianNao();
DianNao dn2 = new DianNao();
String str1 = dn1.chuQuan();
String str2 = dn2.chuQuan();
String result = cp.caiJue(str1, str2);
System.out.println(str1);
System.out.println(str2);
System.out.println(result);
}
}
错误是找不到符号,怎么改。