Chapter 5 Using Conditional Construct
Chapter 5 Using Conditional Construct
Chapter-5
Subjective Question & Answer
1. What are conditional constructs? Name the different types of conditional
constructs.
Ans A conditional construct is a statement that computer programming language
used to decide which code has to be run when the true condition is met or
which code has not to be run when the true condition is not met.
There are three different types of conditional constructs
If-else statement
If-else if statement
Nested if-else statement
3. Give examples of a Java program where the AND logical operator is used.
Ans Program Name – Basketball_TeamA
Import java.util.Scanner;
Class Basketball_TeamA
{
public static void main (String args[])
{
int height=0;
int avg=0;
Scanner Scanner = new Scanner (System.in);
System.out.println(“Enter the candidate’s height in feet: ”);
heights = Scanner.nextInt();
System.out.println(“Enter the average number of baskets per match: ”);
avg = Scanner.nextInt();
if (height>=4 && avg>=3)
{
System.out.println(“Candidate has been shortlisted: ”);
}
else if (height>=4 && avg<3)
{
System.out.println(“Candidate has not been shortlisted: ”);
}
else if (height<4 && avg>=3)
{
System.out.println(“Candidate has been shortlisted: ”);
}
else
{
System.out.println(“Candidate has not been shortlisted ! ”);
}
}
}
TRUE FALSE
1. In the if-else construct, statements included under the “else” code block will be run
2. && is a logical operator that returns true if either of the two conditions is true.
FALSE
3. The if-else if construct is used when more than two conditions are to be tested in a
program. TRUE
executed. FALSE
5. Not (!) logical operator returns true if the operand on right evaluates to true.
FALSE