| English | 意味 |
|---|---|
| algorithm/ˈælɡərɪθəm/ | アルゴリズム |
| high-level language/haɪ ˈlevl ˈlæŋɡwɪdʒ/ | 高レベル言語 |
| compiler/kəmˈpaɪlə/ | コンパイラ |
| syntax error/ˈsɪntæks ˈerə/ | 構文エラー |
| logic error/ˈlɒdʒɪk ˈerə/ | 論理エラー |
A clean build can still sell the wrong price
- A shop program intends to apply a 10% discount to a price of 100, but calculates price * 10 / 100 as the amount to pay.
- It calculates the discount amount, 10, instead of the discounted price, 90. The code can compile and run while implementing the wrong formula.
What is an algorithm?
- An algorithm 算法 is a finite, ordered set of steps that solves a problem. A recipe is an algorithm: precise steps, in order, that finish.
- Programming is the craft of turning an algorithm into code a computer runs. For the finite algorithms taught here, each valid input must lead to a result after finitely many steps. A program may also run an ongoing service; not every program is one terminating calculation.
Programming languages
- Computers run machine code (raw 0s and 1s) — hard for humans to write. We write in a high-level language 高级语言 like Java: readable, English-like.
- Java code says what to do; a translator turns it into machine instructions. This course teaches problem-solving through Java.
Compilers
- A compiler 编译器 such as javac translates Java source files into class files and checks grammar, types and names. Java compiles to bytecode, which the Java Virtual Machine (JVM) then runs.
- "Write once, run anywhere": class files can run on different platforms with a compatible JVM and the required libraries; newer class-file versions need a runtime that supports them. Compile errors (caught before running) differ from run-time errors (caught while running).
アルゴリズムを最も適切に説明するのは...
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
有限かつ順序付けられた手順で完了すること — それがアルゴリズムである。
Javaコンパイラはソースコードを...に変換する。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
Javaはバイトコードにコンパイルされ、JVMがそれを実行する。
コンパイルと実行は成功するが正しくない答えを出すプログラムには...がある。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
コンパイルは正常だが結果が誤っている場合 = ロジックエラー。
構文エラーはJavaプログラムのコンパイルを阻止する。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
破綻した構文 → コンパイラはビルドを拒否する。
エラーなくコンパイルできるプログラムは、必ず正しいとは限らない。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
コンパイラは文法、型、変数名をチェックするが、意図された業務ルールや正しい出力を担保するわけではない。
実行時例外は必ずプログラムを終了させる。例外処理コードがそれに一致して捕捉した場合でも同様である。
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
例外は捕捉されて処理されることもあるが、未捕捉の例外は実行を终止させることができる。
値が 0 の int 変数 zero に対して、ArithmeticException をスローする演算はどれか?
難易度 1/5 · 100 コイン + 今日初回完了時に小ボーナス付与
整数のゼロによる除算は例外をスローしますが、浮動小数点数のゼロによる除算はIEEE浮動小数点数の結果になります。
Kinds of errors
- A syntax error 语法错误 breaks Java's grammar — the compiler refuses to build. A run-time error occurs during execution; an uncaught exception may terminate the program. Integer division by a zero variable throws ArithmeticException, while floating-point division follows different rules.
- A logic error 逻辑错误 runs fine but gives the wrong answer. Debugging is finding and fixing all three.
ソースコードから実行可能なプログラムへ
Javaソースコードが実行可能なプログラムになる様子を見る。
A program that compiles is not automatically correct. The compiler catches syntax and other compile-time errors, including type and name errors. A logic error — wrong formula, wrong condition — compiles cleanly and runs, but produces the wrong result. Always test your algorithm's output, not just whether it builds.
Match each defect to its category.
難易度 2/5 · 140 コイン + 今日初回完了時に小ボーナス付与
The categories depend on when and how the defect is detected; successful compilation does not establish the intended result.
An algorithm to find the larger of two numbers a and b:
- Step 1: if
a > b, the answer isa. - Step 2: otherwise, the answer is
b. - Finite, ordered, and always finishes — a valid algorithm, ready to code in Java.
Carry the reasoning to a new case
- Check discount output against known cases. For this example, 100 should give 90 and 0 should give 0; include a non-round input under a stated rounding policy rather than assuming integer division is decimal arithmetic.
- The compiler also catches type and name errors, not only punctuation mistakes. Conversely, an exception can be handled during execution; a clean compile does not guarantee an intended result or absence of run-time failures.
An algorithm is a finite, ordered set of steps that solves a problem; programming turns it into code. Java is a high-level language that a compiler translates to bytecode for the JVM. Watch for syntax, run-time, and logic errors — a clean compile does not guarantee a correct result.