Test 1

作者: gaoger | 来源:发表于2018-05-07 14:48 被阅读0次

    程序自动生成10道(1-10之间的)加法题,每生成1道,就进行答题,10题答完,自动记分

    ```

    public static void main(String[] args) {

    int score = 0;

    int num1 = 0;

    int num2 = 0;

    Random r = new  Random();

    Scanner sc = new Scanner(System.in);

    for(int i=0; i<10; i++) {

    num1 = r.nextInt(10) + 1;

    num2 = r.nextInt(10) + 1;

    int correctAnswer = num1 + num2;

    System.out.println(num1 + " + " + num2 + " = ");

    System.out.println("Please input the answer");

    int input = sc.nextInt();

    if(input == correctAnswer) {

    score = score + 1;

    }

    }

    System.out.println("Your total score is: " + score);

    }

    ````

    相关文章

      网友评论

          本文标题:Test 1

          本文链接:https://www.haomeiwen.com/subject/iiomrftx.html