爲什麼連錯9題???

心算1.0


      public static void main(String[] args) {
    	  Random random = new Random();
    	  Scanner input = new Scanner(System.in);
    	  int time = 0;
    	  int time1 = 0;
    	  //多次循環
    	  for(int i = 10;i > 1;i--) {
    		  //隨機產生10以內的正整數
    		  int a = random.nextInt(10);
    		  int b = random.nextInt(10);
    		  System.out.print(a + "+" + b + "= " );
    		  //鍵盤輸入答案
    		  int c = input.nextInt();
    		  //電腦計算答案
    		  int result = a + b;
    		  //判斷輸入的答案和真正的答案是否相等
    		  if(result == c) {
    			  System.out.println("回答真確,你已經答對" + ++time + "次。");
    		  }else {
    			  System.out.println("回答錯誤,你已經答錯" + ++time1 + "次。");
    		  }
    	  }
    	  
      }

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章