Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java How To Find Positive or Negative Numbers?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
int myNum = 10; // Is this a positive or negative number? ___ (myNum > 0) {3Order
Put the learning moves in the order that makes the concept easiest to apply.
Explanation: We use simple comparisons with > and < .
Find out if a number is positive or negative:
Find Out if a Number is Positive or Negative
Find Out if a Number is Positive or Negative
Find out if a number is positive or negative:
Example
int myNum = 10; // Is this a positive or negative number? if (myNum > 0) {
System.out.println("The value is a positive number.");
} else if (myNum < 0) {
System.out.println("The value is a negative number.");
} else {
System.out.println("The value is 0.");
}Explanation: We use simple comparisons with > and < . - If the number is greater than 0, it is positive. - If the number is less than 0, it is negative. - If it is neither, it must be exactly 0.