代码:猜数游戏

package guess;

import java.util.Scanner;

public class guess {

public static void main(String[ ]args) {

Scanner in = new Scanner(System.in);

int count = 0;

int a = 0;

int num = (int)(Math.random()*100+1);

System.out.println("请输入一个数:");

while (a!=num)

{

a = in.nextInt();

count = count + 1;

if (a>num)

{

System.out.println("小一些");

}

else if (a

{

System.out.println("大一些");

}

}

System.out.println("你猜对了,这个数是:"+num+";你猜了"+count+"次");

}

}

你可能感兴趣的:(代码:猜数游戏)