- [/code][code]
- package 顏詢大笨蛋1;
- import java.sql.Date;
- import java.time.LocalDateTime;
- import java.util.Scanner;
- public class 顏詢大笨蛋2 {
- // 一個專案只會有一個(程式進入點)
- public static void main(String[] args){
-
- int answer = (int) (Math.random()*99+1);
- System.out.println(answer);
- System.out.println("猜一個1~99以內的數字:(顏詢的智商)");
- int temp = 99;
- int count =1;
- int guess =0;
- while(true) {
- try{
- Scanner scanner = new Scanner(System.in);
- guess = scanner.nextInt();
- }
- catch(Exception ex)
- {
- guess=0;
- }
- if(guess >answer) {
- System.out.println("沒那麼多");
- System.out.println("猜一個1~"+ guess +"以內的數");
- temp = guess;
- count++;
- }
- else if(guess < answer) {
- System.out.println("沒那麼少");
- System.out.println("猜一個"+ guess +"~"+temp+"以內的數");
- count++;
- }
- else {
- System.out.println("猜對了!");
- System.out.println("一共猜了"+ count+"次");
- break;
-
-
- }
-
- }
-
-
-
-
- }
- }
複製代碼 |