Page 118 - CA_Blue( J )_Class10
P. 118
7.2 CONDITIONAL STATEMENTS
Conditional statements allow you to check a condition and execute a certain block of code depending on whether the
condition is true or false. These statements are also known as decision-making or selection statements. Java provides
the following conditional statements:
• if statement
• if…else statement
• if and only if statement
• if…else…if statement
• nested if statement
7.2.1 The if Statement
The if statement is used to handle those situations where depending on some condition a single statement or a block
of statements will execute. If the condition Start
evaluates to true, the block will execute else
will be ignored and the control of the program
is transferred to the statement next to the if temperature=-1;
statement. The syntax of the if statement is:
int temperature=-1;
if(condition)
Condition: true Below
{
if(temperate<0) Freezing point
Statements;
}
Example of the if statement is: false
int temperature=-1; End
if (temperature < 0)
{
System.out.println("Below Freezing Point");
}
Note: You can use if statement without curly bracket, if your code contains only one statement inside
the body of the if statement.
To input the basic salary of a person and print the total salary he will be getting after adding the
Program 2
Dearness Allowance of 50% with basic salary. If the total salary is more than Rs.20,000, then
the 5% tax will be deducted from the total salary.
1 import java.util.*;
2 class income_tax
3 {
4 public static void main()
5 {
6 Scanner sc= new Scanner(System.in);
7 double bs,da,t,ts,tax=0.0;
8 System.out.println("Enter the Basic Salary : ");
9 bs = sc.nextDouble();
10 da = 0.5 * bs;
116116 Touchpad Computer Applications-X

