Created
September 26, 2012 05:15
-
-
Save fanker/3786235 to your computer and use it in GitHub Desktop.
猜数字小游戏
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CaiShu { | |
public static void main (String[] args) { | |
java.util.Scanner input = new java.util.Scanner(System.in); | |
System.out.println("请输入数字:"); | |
int a = 55; | |
int i = 0; | |
while (true) { | |
int num = input.nextInt(); | |
i++; | |
if (a > num) { | |
System.out.println("数字太小,再试试!"); | |
System.out.println("请输入数字:"); | |
}else if (a < num) { | |
System.out.println("数字太大,再试试!"); | |
System.out.println("请输入数字:"); | |
}else { | |
System.out.println("恭喜你猜对了!"); | |
break; | |
} | |
} | |
if (i <5) { | |
System.out.println("你总共用了" + i + "次,真棒!"); | |
}else { | |
System.out.println("你总共用了" + i + "次,请继续努力!"); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment