If else Control Structure

If else Control Structure


The if else control structure is used where either of two action are to be performed depending upon the result of a conditional expression. It contains two block of statement. If the conditional expression evaluates to true, the statement(s) in if block are executed and if the result is false, then statement(s) in the else block get executed.

Syntax:

if(conditional expression)
{
statement 1
statement 2
……………
}
else
{
statement 1
statement 2
……………
}

Java : If else Control Structure Program List




Program [1]

Write a program to check whether a short type number taken as input is an even number or an odd number.


View Solution


Program [2]

Write a program to accept an int type value as a parameter and print the square of it, if it is more than 120, otherwise print its cube.


View Solution


Program [3]

Write a program to input 5 real numbers(floating point) and find their average. If the average is greater than 50 print good, otherwise print bad.


View Solution


Program [4]

Write a program to check whether an int type number (taken as input) is a multiple of 5 or not.


View Solution


Program [5]

Write a program to check whether an int type number (taken as input) is a 2-digit number or not.


View Solution


Program [6]

Write a program to check whether an int type number (taken as input) is a 3-digit number divisible by three or not.


View Solution


Program [7]

Write a program to input 2 integers and check whether both the numbers are multiples of 7 or not.


View Solution


Program [8]

Write a program to input three integers and check whether all of them are unique (different) from each other or not.


View Solution


Program [9]

Write a program to input an integer and check whether it is a 5-digit number or not. If it is extract the central digit and print it.

Example

INPUT: Enter an integer: 76549

OUTPUT: Central digit: 5

INPUT: Enter an integer: 12976

OUTPUT: Central digit: 9

INPUT: Enter an integer: 126

OUTPUT: Not a 5 digit number


View Solution