[java]代码库
import java.util.Scanner;
/**
* 猜数字游戏
*
*/
public class MonkeyGuess {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int num = (int) (Math.random() * 100);
int m = 0;
for (int i = 9; i >= 0; i--) {
System.out.println("please input your number! ");
m = s.nextInt();
if (m > num) {
System.out.println("Too large!");
} else if (m < num) {
System.out.println("Too small!");
} else {
System.out.println("You are right!");
break;
}
if (i > 0) {
System.out.println("还有" + i + "次机会!");
}
}
if (m != num) {
System.out.println("下次再来吧!");
}
}
}
初级程序员
by: 幻想不死鸟 发表于:2012-10-22 13:57:01 顶(1) | 踩(0) 回复
网友回复
回复小蜜锋 : 额
顶(1) 踩(0) 2012-10-22 20:41:59
回复评论