You are on page 1of 7

Experiment No 03:- Develop programs to demonstrate use of in statements and its different

forms
Q1. Create a program to find the smallest number among three numbers.
Ans : Code-
public class Smallestnumber
{
public static void main(String[] args)
{
int a=99, b=89, c=190;
if(a<=b && a<=c)
System.out.println(a+" is the smallest number");
else if (b<=a && b<=c)
System.out.println(b+" is the smallest number");
else
System.out.println(c+" is the smallest number");
}
}

Input-

Output-
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms

Q2. List operators used in if conditional statements.


Ans : The Operators used in if conditional statements are:
1)Relational operators ( >= , <= , == )
2)Boolean operators ( true , false)
3)Logical operators ( && , || , | )

Q3. In the if-else construct which part will be executed if the condition is true.
Ans : In if else if the condition if true the if part will only be executed.

Q4. Which of the following operator is used in if:


i) Assignment operator ( = ) ii) comparison operator ( == )
Ans : ii) comparison operator ( == )

Q5. Write a program to check no is even or odd.


Ans : Code-
import java.util.Scanner;
class even_odd
{
public static void main(String args[])
{
int num;
System.out.println("Enter one number:");
Scanner input = new Scanner(System.in);
num = input.nextInt();
if ( num % 2 == 0 )
System.out.println("Entered number is even");
else
System.out.println("Entered number is odd");
}
}

Input-
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms
Output-

Q6. Write a program to make the use of logical operators.


Ans :
Code for And Logical Operator-
import java.io.*;

class Logical {
public static void main(String[] args)
{
int a = 50, b = 10, c = 26, d = 8;
System.out.println("Var1 = " + a);
System.out.println("Var2 = " + b);
System.out.println("Var3 = " + c);
if ((a < b) && (b == c)) {
d = a + b + c;
System.out.println("The sum is: " + d);
}
else
System.out.println("False conditions");
}
}
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms

Input-

Output-
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms

Code for Or Logical Operator-


public class OrLogical
{
public static void main(String[] args)
{
int x = 2;
int y = 8;
int z = 1;
System.out.println("x: " +(x==1));
System.out.println("y: " +(y==z));
System.out.println("z>x: " +(z>x));
if(x==1 || x>y || x>z)
{
System.out.println("One");
}
if(x==y || y==2 || z==5)
{
System.out.println("Two");
}
if(x==y || y==z || z==x)
{
System.out.println("Three");
}
}
}

Input-
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms
Output-

Code for Not Logical Operator-


import java.io.*;
class LogicalNot
{
public static void main(String[] args)
{
int a = 20, b = 3;
System.out.println("Var1 = " + a);
System.out.println("Var2 = " + b);
System.out.println("!(a < b) = " + !(a < b));
System.out.println("!(a > b) = " + !(a > b));
}
}

Input-
Experiment No 03:- Develop programs to demonstrate use of in statements and its different
forms
Output-

You might also like