したがって、4番目の方法で勝者を決定しようとしていますが、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;
}
}