學習進度條:java
點滴成就 | 學習時間 | 新編寫代碼行數 | 博客量(篇) | 學到知識點 |
第一週 | 8 | 0 | 0 | 瞭解軟件工程 |
第二週 | 10 | 0 | 1 | 博文一篇 |
第三週 | 15 | 0 | 2 | 選擇項目、調查問卷 |
第四周 | 20 | 80 | 0 | 結對編程 |
第五週 | 25 | 330 | 1 | java的學習、軟件工程 |
第六週 | 25 | 210 | 0 | 編譯原理、軟件工程 |
第七週 | 15 | 0 | 0 | 軟件系統設計 |
1.題目描述:某公司程序員二柱的小孩上了小學二年級,老師讓家長天天出30道(100之內)四則運算題目給小學生作。二柱立馬就想到寫一個小程序來作這件事。 這個事情能夠用不少語言或者工具來實現:程序員
package arithmetic; import java.util.Random; import java.util.Scanner; public class Arithmetic { private static Scanner input = new Scanner(System.in); public static void main(String[] agrs) { int choose; int right = 0; int first = 0; int last = 0; int[] error = new int[30]; int[] errorId = new int[30]; int oper, j = 0, k = 0; int result1 = 0; int result2 = 0; Random random = new Random(); while (true) { System.out.print("是否進行運算: 1.是 2.否\n"); choose = input.nextInt(); if (choose == 1) { for (int i = 0; i < 30; i++) { Scanner input1 = new Scanner(System.in); first = random.nextInt(100); last = random.nextInt(100); oper = random.nextInt(4); switch (oper) { case 0: { System.out.print(i + 1 + ". " + first + "+" + last + "="); result1 = input1.nextInt(); result2 = first + last; if (result1 == result2) right++; else { error[j] = result2; errorId[k] = i + 1; j++; k++; } break; } case 1: { while (first < last) { first = random.nextInt(100); last = random.nextInt(100); } System.out.print(i + 1 + ". " + first + "-" + last + "="); result1 = input1.nextInt(); result2 = first - last; if (result1 == result2) right++; else { error[j] = result2; errorId[k] = i + 1; j++; k++; } break; } case 2: { System.out.print(i + 1 + ". " + first + "*" + last + "="); result1 = input1.nextInt(); result2 = first * last; if (result1 == result2) right++; else { error[j] = result2; errorId[k] = i + 1; j++; k++; } break; } case 3: { if (last == 0) { last = random.nextInt(99) + 1; } while (first % last != 0) { first = random.nextInt(100); last = random.nextInt(99) + 1; } System.out.print(i + 1 + ". " + first + "/" + last + "="); result1 = input1.nextInt(); result2 = first / last; if (result1 == result2) right++; else { error[j] = result2; errorId[k] = i + 1; j++; k++; } break; } } } System.out.print("你一共答對了" + right + "道題\n" + "其中錯誤的題和其正確答案爲:\n"); for (int m = 0; m < j; m++) { System.out.print(errorId[m] + ". " + error[m] + " "); System.out.print("\n"); } } } } }
4.結果編程
5.總結:小程序