所以在第四种方法我试图确定赢家,但它说int不能转换为java.lang.String 是的,我必须使用不同的方法,如果你发现别的错误的代码让我知道,谢谢你不兼容的类型:int不能转换为java.lang.String
import java.util.Random;// importing the random class to generate random number
import javax.swing.JOptionPane;//importing the JOptionPane to use the pop up windows and menu
public class TiriBark
{
private static int ComputerWin =0; // 0 is for loss and 1 for win
private static int UserWins =0; // 0 is for loss and 1 for win
private static int tie=0; // if it's a tie the value will be 1
private static int Comp; // holds the value of the random number generated by the computer
private static int user; // holds users choice of rock papper or scissor
public static void main(String[] args) // main method
{
Computer();
user();
}
/**this method generated a random number between 1 and 3
*@return Comp
*/
public static int Computer()
{
Random rand = new Random();
int Comp = rand.nextInt(3)+1;
return Comp;}
/**this method asked the user to enter his choice of rock paper or scissor
*@return user
*/
public static int user(){
String User = JOptionPane.showInputDialog("Enter 1 for rock 2 for paper and 3 for scissor ");
int user = Integer.parseInt(User);
return user; }
/** this method calculates and determines the winner and if possible a tie
*@return ComputerWin
*@return UserWins
*@return tie
*/
public static String resutls() {
if (user == Comp) {
tie =1; }
if (user==1 && Comp == 2){
ComputerWin=1; }
if (user ==1 && Comp ==3){
UserWins=1;}
if (user ==2 && Comp ==1){
UserWins=1;}
if (user ==2 && Comp == 3){
ComputerWin=1;}
if (user ==3 && Comp ==1) {
ComputerWin=1; }
if (user ==3 && Comp ==2){
UserWins=1;}
return UserWins;
return ComputerWin;
return tie;
}
}
从'resutls()'返回的所有值都是'int'值。我建议使方法的返回类型为'int' –
你想返回3个值吗? – bradimus
是的bradimus,但我猜这是不可能的 –