在网上找来练手的小代码——猜大小游戏~~~~分享给各位,学习的捷径是——学习他人的代码,勤敲代码!!!
import java.util.Random;
import java.util.Scanner;
public class caidx
{
public static void main(String[] args)
{
Random r=new Random();
int dianshu=r.nextInt(6);
dianshu++;
System.out.println("==== 猜大小游戏 ====");
Scanner s=new Scanner(System.in);
System.out.println("请输入“大”或者“小”");
String daxiao=s.next();
if(dianshu<=3&&daxiao.equals("小")){System.out.println("点数是"+dianshu+"。你猜的是"+daxiao+"。恭喜你,猜对了!");}
if(dianshu<=3&&daxiao.equals("大")){System.out.println("点数是"+dianshu+"。你猜的是"+daxiao+"。Sorry,猜错了。");}
if(dianshu>3&&daxiao.equals("大")){System.out.println("点数是"+dianshu+"。你猜的是"+daxiao+"。恭喜你,猜对了!");}
if(dianshu>3&&daxiao.equals("小")){System.out.println("点数是"+dianshu+"。你猜的是"+daxiao+"。Sorry,猜错了。");}
if(!(daxiao.equals("大")||daxiao.equals("小"))){System.out.println("只能输入“大”或者“小”");}
}
}
===========================
|
|