import java.util.*;
import javax.swing.*;public class game1
{
public static void main(String[] args)
{ //Comment on what variable are
int Userinput, ComputerChoice, result;
int rock = 0;
String Userinput_str;
Userinput_str = JOptionPane.showInputDialog("0 = rock\n\n" +
"1 = scissor " + "\n\n" +
"2 = paper" + "\n\n"+"your guess");
Userinput = Integer.parseInt(Userinput_str); Random generator = new Random(); ComputerChoice = generator.nextInt(3); result = Userinput - ComputerChoice; while(Userinput == 0 || Userinput == 1 || Userinput == 2 )
{ if(result == ComputerChoice)
{
System.out.println("Your Choice is as same as ComputerChioce's, Try again");
}
else
{
if(Userinput == 0 && ComputerChoice == 1 && result == -1)
System.out.println("You Win, rock smashes scissor"); if(Userinput == 0 && ComputerChoice == 2 && result == -2)
System.out.println("Computer Win, paper smothers rock"); if(Userinput == 1 && ComputerChoice == 2 && result == -1)
System.out.println(" You Win, scissor cuts paper"); if(Userinput == 1 && ComputerChoice == 0 && result == 1)
System.out.print("Computer Win, rock smashes csissor"); if(Userinput == 2 && ComputerChoice == 1 && result == 1)
System.out.println("Computer Win, scissor cuts paper"); if(Userinput == 2 && ComputerChoice == 0 && result == 2)
System.out.println("You win, paper smothers rock"); }
}
System.exit(0);
}
}
import javax.swing.*;public class game1
{
public static void main(String[] args)
{ //Comment on what variable are
int Userinput, ComputerChoice, result;
int rock = 0;
String Userinput_str;
Userinput_str = JOptionPane.showInputDialog("0 = rock\n\n" +
"1 = scissor " + "\n\n" +
"2 = paper" + "\n\n"+"your guess");
Userinput = Integer.parseInt(Userinput_str); Random generator = new Random(); ComputerChoice = generator.nextInt(3); result = Userinput - ComputerChoice; while(Userinput == 0 || Userinput == 1 || Userinput == 2 )
{ if(result == ComputerChoice)
{
System.out.println("Your Choice is as same as ComputerChioce's, Try again");
}
else
{
if(Userinput == 0 && ComputerChoice == 1 && result == -1)
System.out.println("You Win, rock smashes scissor"); if(Userinput == 0 && ComputerChoice == 2 && result == -2)
System.out.println("Computer Win, paper smothers rock"); if(Userinput == 1 && ComputerChoice == 2 && result == -1)
System.out.println(" You Win, scissor cuts paper"); if(Userinput == 1 && ComputerChoice == 0 && result == 1)
System.out.print("Computer Win, rock smashes csissor"); if(Userinput == 2 && ComputerChoice == 1 && result == 1)
System.out.println("Computer Win, scissor cuts paper"); if(Userinput == 2 && ComputerChoice == 0 && result == 2)
System.out.println("You win, paper smothers rock"); }
}
System.exit(0);
}
}
解决方案 »
- 按要求定义一个操作类:要求完成一个数组操作类,其中可以加入任意类型的数据,数组具体的操作类型由外部决定,并且可以实现查询功能。
- jnlp发布jar包,调用资源文件的问题,等高人来帮忙!!!
- 我想这样双向移动
- 招聘.net winform开发人员
- java图片处理问题,求高手帮忙
- 现在学java 不知道从哪里下手,高手指点
- 高手来啊!
- 100高分请进:regex = "\\s[Hh][Rr][Ee][Ff]\\s*=\\s*\"([^\\.#(http)]+[^\">]*)\"";...
- 安装了j2ee,j2se.可是找不到相关的启动图标(吐血求救)
- 如何得到系统所有的盘符,并且判断是不是光区和软区(解决就给分)
- 有没有办法模拟鼠标左键点击事件??
- JAVA有切除小数点后面的函数么(不是四舍五入),谢谢。
import javax.swing.*;public class game1{
public static void main(String[] args){ //Comment on what variable are
int Userinput, ComputerChoice, result;
int rock = 0;
String Userinput_str;
Userinput_str = JOptionPane.showInputDialog("0 = rock\n\n" +
"1 = scissor " + "\n\n" +
"2 = paper" + "\n\n"+"your guess");
Userinput = Integer.parseInt(Userinput_str);
Random generator = new Random(); ComputerChoice = generator.nextInt(3); result = Userinput - ComputerChoice;
while(Userinput == 0 || Userinput == 1 || Userinput == 2 ) { if(result == ComputerChoice)
{ System.out.println("Your Choice is as same as ComputerChioce's, Try again");
}
else {
if(Userinput == 0 && ComputerChoice == 1 && result == -1)
System.out.println("You Win, rock smashes scissor");
if(Userinput == 0 && ComputerChoice == 2 && result == -2)
System.out.println("Computer Win, paper smothers rock");
if(Userinput == 1 && ComputerChoice == 2 && result == -1)
System.out.println(" You Win, scissor cuts paper");
if(Userinput == 1 && ComputerChoice == 0 && result == 1)
System.out.print("Computer Win, rock smashes csissor");
if(Userinput == 2 && ComputerChoice == 1 && result == 1)
System.out.println("Computer Win, scissor cuts paper");
if(Userinput == 2 && ComputerChoice == 0 && result == 2)
System.out.println("You win, paper smothers rock");
}
Userinput_str = JOptionPane.showInputDialog("0 = rock\n\n" +
"1 = scissor " + "\n\n" +
"2 = paper" + "\n\n"+"your guess");
Userinput = Integer.parseInt(Userinput_str);
generator = new Random();
ComputerChoice = generator.nextInt(3);
result = Userinput - ComputerChoice;
}
System.exit(0);
}}