| English | 의미 |
|---|---|
| Boolean expression/ˈbuːlɪən ekˈspreʃn/ | 부울表达式 |
| relational operators/rɪˈleɪʃənl ˈɒpəreɪtəz/ | 관계 연산자 |
true or false
- A Boolean expression 布尔表达式 evaluates to exactly one of two values:
trueorfalse. - Conditions in
ifstatements and loops are Boolean expressions. - Store one in a
booleanvariable:boolean passed = score >= 60; - Everything in selection and repetition rests on these
true/falseresults.
Relational operators
- Relational operators 关系运算符 compare two values and give a Boolean:
<less than,<=at most,>greater than,>=at least.==equal to,!=not equal to.5 > 3istrue;4 == 5isfalse.
== versus =
==tests equality;=assigns — completely different jobs.x == 5asks "isxequal to5?" and givestrue/false.x = 5stores5inx.- Using
=where you meant==is a classic bug (and often a compile error in a condition).
Predicting the value
- To evaluate a Boolean expression, plug in the values and apply the operator.
- With
x = 7:x < 10→true;x == 7→true;x != 7→false. - Read the operator carefully —
<=includes equality,<does not. - Being able to predict the result is the core skill for tracing code.
== compares; = assigns — never confuse them in a condition. if (x = 5) is wrong (it assigns, not compares); you want if (x == 5). And mind the boundary operators: x <= 10 is true when x is exactly 10, but x < 10 is false — an off-by-one that flips many conditions.
With int age = 18;:
age >= 18→true(18 is at least 18).age > 18→false(18 is not greater than 18).age == 18→true;age != 20→true.
A Boolean expression evaluates to true or false, using relational operators < <= > >= == !=. Remember == tests equality while = assigns, and that <=/>= include the boundary but </> don't. Store a result in a boolean variable to reuse it.
부울리안 결과
부울리안 식은 참(true, 1) 또는 거짓(false, 0)으로 평가됩니다.
두 값이 같은지 테스트하는 연산자는 무엇입니까?
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
==는 등가성을 테스트하고; =는 할당을 의미합니다.
int age = 18;일 때, expression age > 18은 참입니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
18은 18보다 크지 않으므로; age >= 18이라면 참이 됩니다.
int x = 7;일 때, expression x <= 7은 참입니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
<=는 등가를 포함하므로, 7 <= 7은 참입니다.
5 != 5는 어떤 값으로 평가됩니까?
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
!=는 '등가가 아님'을 의미합니다; 5는 5와 같으므로 거짓입니다.
참 또는 거짓을 저장하는 변수의 타입은 ___ (한 단어)입니다.
난이도 1/5 · 100 코인 + 오늘 첫 완료 시 소액 보너스
boolean은 true/false를 유지합니다.