我有一個快速的問題,所以我完成了我的程序,這是一個簡單的岩石,剪刀遊戲,但目前它只顯示0,1,2其中0是剪刀,1是岩石,2是紙。我所面臨的問題是,我不太清楚如何給用戶提供輸入,以及計算機輸出從顯示數字到顯示剪刀,搖滾,紙張等。將數字輸出和輸入轉換爲字
import java.util.Scanner;
import java.lang.Math;
public class Lab3
{
public static void main(String[] args)
{
Scanner in = new Scanner(System.in);
System.out.print("Hello user! lets play ");
System.out.println("Rock, Paper, Scissors.");
System.out.println();
System.out.print("Type in 0 for Scissors, 1 for Rock, or 2 for Paper ");
int userInput = in.nextInt();
int opponentsHand = (int)(Math.random()*3);
if (userInput == opponentsHand)
{
System.out.print("Darth Vader has played " + opponentsHand);
System.out.println(" Despite your efforts of playing " + userInput + ", this battle has ended in a draw!");
}
if (userInput < opponentsHand && opponentsHand != 2)
{
System.out.print("Darth vader has played "+ opponentsHand);
System.out.println(", You played " + userInput + "You have Lost");
}
else if (userInput < opponentsHand && opponentsHand == 2)
{
System.out.print("Darth Vader has played " + opponentsHand);
System.out.println(" You played " + userInput + " You have won");
}
if (userInput > opponentsHand && opponentsHand != 0)
{
System.out.print("Darth Vader has played " + opponentsHand);
System.out.println(" You have played " + userInput + " You have won");
}
else if (userInput > opponentsHand && opponentsHand == 0)
{
System.out.print("Darth Vader has played " + opponentsHand);
System.out.println(" You have played " + userInput + " You have lost");
}
}
}
謝謝
這對d有什麼影響? o與JavaScript? – ndugger 2014-10-04 04:19:01