You are on page 1of 3

Practical No.

3
Program Code: To check multiple condition with if statement

class example {

public static void main(String[] args) {

int a = 10;

int b = 15;

if (a > 9)

if(b >= 10){

System.out.println("This is a nested if");

}}}}

Exercise:
1.
class Nestedif{

public static void main(String[] args) {

int num = 70;

if (num < 100){

System.out.println("Number is less than 100");

if(num > 50){

System.out.println("Number is greater than 50");

}}}}

2.
class Ifstatement {
public static void main(String[] args) {

int num = 10;

if (num > 0){

System.out.println("Number is positive");

}else

System.out.println("Number is negative");

}}

3. Write a program to make use of logical operators


class Test{

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a && b = "+(a&&b));

System.out.println("a || b = "+(a||b));

System.out.println("!(a && b) = "+!(a||b));

4. Write a program to check number is even or odd


class Test{

public static void main(String[] args) {

boolean a = true;

boolean b = false;

System.out.println("a && b = "+(a&&b));

System.out.println("a || b = "+(a||b));

System.out.println("!(a && b) = "+!(a||b));


}}

You might also like