Biểu thức và Đầu ra
Đã giới thiệu| English | Ý nghĩa |
|---|---|
| expression/ekˈspreʃn/ | biểu thức |
| operators/ˈɒpəreɪtəz/ | toán tử |
| modulus/ˈmɒdjʊləs/ | phép chia lấy dư |
| concatenates/kənˈkætəneɪts/ | nối chuỗi |
Arithmetic expressions
- An expression 表达式 is a piece of code that computes a value.
- Java's arithmetic operators 运算符:
+,-,*,/, and%(remainder). %is the modulus 取模 operator:17 % 5is2(the leftover after dividing).- Expressions follow the usual order of operations (
*,/,%before+,-).
Precedence and grouping
- Multiplication and division bind tighter than addition and subtraction.
- Use parentheses to force the order you want:
(a + b) * c. - Operators of equal precedence evaluate left to right.
- When in doubt, add parentheses — clarity beats cleverness.

print stays on the line, println ends it; + adds numbers until a String appears
Printing output
System.out.println(x)printsxand moves to a new line.System.out.print(x)printsxwith no new line after.- The
+operator concatenates 拼接 strings:"Score: " + score. - Mixing a String with a number in
+turns the number into text.
String concatenation vs. addition
- If either side of
+is a String,+means concatenation, not addition. "" + 3 + 4gives"34"(text), but3 + 4 + ""gives"7"(added first).- Evaluation is left to right, so the first
+decides the mode. - Wrap numeric math in parentheses when concatenating:
"Sum: " + (3 + 4).
+ is overloaded: it adds numbers but concatenates Strings, left to right. "Total: " + 3 + 4 prints Total: 34 (each + hits a String), while "Total: " + (3 + 4) prints Total: 7. And % gives the remainder — great for "is it even?" (n % 2 == 0) — don't confuse it with division.
Evaluate 10 + 2 * 3:
*first:2 * 3is6.- Then
+:10 + 6is16. System.out.println("Answer: " + 16)printsAnswer: 16.
An expression computes a value using operators + - * / % under standard precedence (* / % before + -, left to right, parentheses override). % gives the remainder. Print with System.out.println (newline) or print (none); + concatenates when a String is involved — parenthesize numeric math.
Đánh giá biểu thức từng bước
- gắn chặt hơn +, nên 2*3 xảy ra trước.
Đánh giá biểu thức Java 10 + 2 * 3.
Độ khó 2/5 · 140 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
- trước (2*3=6), sau đó + (10+6=16).
17 % 5 trong Java (phần dư) là bao nhiêu?
Độ khó 2/5 · 140 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
17 = 3×5 + 2, nên phần dư là 2.
System.out.println("Total: " + 3 + 4) in ra gì?
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
Từ trái sang phải, mỗi + gặp String → nối chuỗi → 34.
Toán tử trả về phần dư của phép chia là ___ (một ký tự).
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
% là toán tử modulus (phần dư).
System.out.print(x) chuyển sang dòng mới sau khi in.
Độ khó 1/5 · 100 xu + một phần thưởng nhỏ cho lần hoàn thành đầu tiên trong ngày
print giữ ở cùng dòng; println thêm dấu xuống dòng.