首页 > 代码库 > JAVA小程序:和电脑猜拳
JAVA小程序:和电脑猜拳
import java.util.Scanner;
import java.util.Random;
public class Hello {
public static int judge(int j, int k)
{
int m;
if(j==k) m=0;
else if(j==0&&k==2||j==1&&k==0||j==2&&k==1) m=1;
else m=2;
return m;
}
public static void main(String[] args) {
System.out.println("scissor(0),rock(1),paper(2)");
System.out.println("Please Input Your Choose:");
int a=0,b=0;
Scanner input = new Scanner(System.in);
while(a!=2&&b!=2)
{
int Choose = input.nextInt();
int number = new Random().nextInt(3);
if (judge(Choose,number)==0)
{System.out.println("平手,please continue competition");
continue;}
else if(judge(Choose,number)==1)
{ System.out.println("You win this time,please continue competition");
a++;}
else if(judge(Choose,number)==2)
{ System.out.println("You are defeabed this time,please continue competition");
b++;
}
}
if(a==2)
System.out.println("You Win Last");
else if(b==2)
System.out.println("Computer Win Last");
}
}
import java.util.Random;
public class Hello {
public static int judge(int j, int k)
{
int m;
if(j==k) m=0;
else if(j==0&&k==2||j==1&&k==0||j==2&&k==1) m=1;
else m=2;
return m;
}
public static void main(String[] args) {
System.out.println("scissor(0),rock(1),paper(2)");
System.out.println("Please Input Your Choose:");
int a=0,b=0;
Scanner input = new Scanner(System.in);
while(a!=2&&b!=2)
{
int Choose = input.nextInt();
int number = new Random().nextInt(3);
if (judge(Choose,number)==0)
{System.out.println("平手,please continue competition");
continue;}
else if(judge(Choose,number)==1)
{ System.out.println("You win this time,please continue competition");
a++;}
else if(judge(Choose,number)==2)
{ System.out.println("You are defeabed this time,please continue competition");
b++;
}
}
if(a==2)
System.out.println("You Win Last");
else if(b==2)
System.out.println("Computer Win Last");
}
}
JAVA小程序:和电脑猜拳
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。