猜数游戏
import java.util.Scanner;
?
public class GuessNum {
?public static void main(String[] args) {
??Scanner s = new Scanner(System.in);??//接受輸入(猜數)
??int user = 0;???????//用戶輸入的數(小)
??int user2 = 100;??????//用戶輸入的數(大)
??int no = -1 ;???????//存放輸入的數
??
??/*生成隨機數,給用戶猜*/
??double d = Math.random();????
??int guess = (int)(d*100)/1;
??
??/*對比用戶猜到數和生成的數*/
??for(;no!=guess;){
???System.out.println("please input a number in "+user+" to "+user2+"!");
???System.out.print("please input a number which you guess:");
???no = s.nextInt();
???if(no>guess){
????System.out.println("too big!");?
????user2 = no;
???}
???if(no<guess){
????System.out.println("too small!");
????user = no;
???}
??}
??System.out.println("congratulation!");
??
?}
}
轉載于:https://www.cnblogs.com/HuangWj/p/4275076.html
總結
- 上一篇: windows下,怎么轻易拷贝一个文件的
- 下一篇: iOS推送小结--swift语言