Professional Documents
Culture Documents
If Statement
If Statement
ANSWER: NOTHING
• Which word in the dictionary is
spelled incorrectly?
• Which word in the dictionary is
spelled incorrectly?
ANSWER: INCORRECTLY
• What gets broken without being held?
• What gets broken without being held?
ANSWER: PROMISE
• He has married many women, but has
never been married. Who is he?
• He has married many women, but has
never been married. Who is he?
ANSWER: A PRIEST
• What has roots as nobody sees,
Is taller than trees.
Up, up, up it goes,
And yet never grows?
• What has roots as nobody sees,
Is taller than trees.
Up, up, up it goes,
And yet never grows?
ANSWER: MOUNTAIN
• I am the beginning of eternity, the end
of time and space. the beginning of
every end, and the end of every place.
What am I?
• I am the beginning of eternity, the end
of time and space. the beginning of
every end, and the end of every place.
What am I?
Syntax:
If (<Boolean condition>)
{
<statement/s>
}
Example:
1 public class If_Statement
2{
3 public static void main(String[] args)
4 {
5 int x=0;
6 System.out.pintln(“Value is: “+x);
7 If (x%2==0)
8 {
9 System.out.println(“Value is an even number.”);
10 }
11 if(x%2==1)
12 {
13 System.out.println(“Value is an odd number.”);
14 }
15 }
16 }
Line 7
If (x%2==0)
Line 7 shows the “if” statement and its
condition. If the remainder when “x” is
divided by 2 is equal to 0, line 8 is
executed. Otherwise, it will immediately go
to next line after the close brace that marks
the end of the scope of the if statement: line
11.
Line 8-10
{
Systemn.out.println(“Value is an even number.”);
}
Test Data
Enter your grade: 83
passed
Exercises
Exercise 1: Write Java program to allow the
user to input his/her age. Then the program
will show if the person is eligible to vote. A
person who is eligible to vote must be older
than or equal to 18 years old.
Test Data
Enter your age: 18
You are eligible to vote.
Exercise 2: Write a Java program that
keeps a number from the user and
generates an integer between 1 and 7
and displays the name of the weekday.
Test Data
Input number: 3
Expected Output :
Wednesday
Task
Direction: Write this program on ¼ sheet of
paper. You can use any style of writing program
as long as it displays the same result. Time
allotment: 8 minutes.
Input base: 3
Input height: 2
Area: 3
Write a program that determines a
comparison between two group of
numbers using symbol <, >, and =.
Answer: >
• Study the else if statement on your
notebook.
Agreement
Problem #1
Write a program that automatically
computes for the perimeter of the rectangle.
Enter length: 10
Enter width: 5
Perimeter: 30
Problem #2
Make a program that gives you option of
beverages and lets you select from it.
Enter selection: 2
Beverage: softdrinks
Problem #3
Write a program that computes the cube
of the given number.
Enter number: 3