You are on page 1of 14

Registration Number – 21BCE0747

Name – Aditya Dhanraj


Slot – L39+L40+L59+L60
Date – 26/7/2022
Assignment – Java Lab – 2 – Operator

(Question number – 9,10,11,12,13,14,15,16)

9. Prepare a Payroll of an employee Basic pay (BP), DA (25% of BP), HRA(10%


of BP), CCA (Rs.500) and the deduction of LIC(1% of BP), PF(2% of BP) and
calculate the Gross pay and net pay

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter Basic pay: ");
float basic_pay=sc.nextFloat();
double DA=(0.25)*basic_pay;
double HRA=(0.1)*basic_pay;
float CCA=500;
double LIC=(0.01)*basic_pay;
double PF=(0.02)*basic_pay;
double grosspay=basic_pay+DA+HRA+CCA;
double netpay=grosspay-LIC-PF;
System.out.println("Grosspay: "+grosspay);
System.out.println("Netpay: "+netpay);
}

10. Program to find out biggest of two numbers

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers: ");
int a=sc.nextInt();
int b=sc.nextInt();
if(a>b)
{
System.out.println(a+" is greatest");
}
else if(a<b)
{
System.out.println(b+" is greatest");
}
else
{
System.out.println(a+" is equal to "+b);
}
}
}

11. Program to find the smallest of three given numbers.

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter three numbers: ");
int a=sc.nextInt();
int b=sc.nextInt();
int c=sc.nextInt();
if (a<b && a<c)
{
System.out.println(a+" is smallest");
}
else if (b<a && b<c)
{
System.out.println(b+" is smallest");
}
else if(c<a && c<b)
{
System.out.println(c+" is smallest");
}
}
}
12. Program to find whether a given number is odd/even and +ve /-ve.

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter a number: ");
int a=sc.nextInt();
if (a%2==0)
{
System.out.println(a+" is even\n");
}
else if (a%2!=0)
{
System.out.println(a+" is odd\n");
}
if(a>0)
{
System.out.println(a+" is positive\n");
}
else if (a<0)
{
System.out.println(a+" is negative\n");
}
else if(a==0)
{
System.out.println(a+" is zero");
}

}
}

13. Program to exchange the values of two variables.

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter two numbers: ");
int a=sc.nextInt();
int b=sc.nextInt();
//Method-1
// int temp=0;
// temp=a;
// a=b;
// b=temp;

//Method-2
a=a+b;
b=a-b;
a=a-b;

System.out.println("Swapped values: ");


System.out.println(a);
System.out.println(b);
}
}
14. Program to find the roots of a given quadratic equations.

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("ax^2 + bx +c. Enter a,b and c");
float a=sc.nextFloat();
float b=sc.nextFloat();
float c=sc.nextFloat();
double disc=Math.pow(b,2)-4*a*c;
double srtdisc=Math.sqrt(disc);
double x1= (-b+srtdisc)/(2*a);
double x2= (-b-srtdisc)/(2*a);

System.out.println("Roots: ");
System.out.println(x1);
System.out.println(x2);

}
}
15.Write a program to compute grade of students using if else ladder. The
grades are assigned as following
Marks Grade
Marks<50 F
50≤marks< 60 C
60≤marks<70 B
70≤marks<80 B+
80≤marks<90 A
90≤mars≤ 100 A+

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter your marks: ");
float a=sc.nextFloat();
if(a>=0 && a<50)
{
System.out.println("Grade: F");
}
else if(a>=50 && a<60)
{
System.out.println("Grade: C");
}
else if(a>=60 && a<70)
{
System.out.println("Grade: B");
}
else if(a>=70 && a<80)
{
System.out.println("Grade: B+");
}
else if(a>=80 && a<90)
{
System.out.println("Grade: A");
}
else if(a>=90 && a<=100)
{
System.out.println("Grade: A+");
}
else
{
System.out.println("Invalid Marks");
}
}
}
16. Write a program to check whether the entered year is leap year or not (a
year is leap if it is divisible by 4 and divisible by 100 or 400.)

import java.util.*;
public class operator{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);
System.out.println("Enter year: ");
int year=sc.nextInt();
if(year%400==0)
{
System.out.println("Leap Year");
}
else if(year%400!=0 && year%100==0)
{
System.out.println("Not a leap year");
}
else if(year%4==0 && year%100!=0)
{
System.out.println("Leap Year");
}
else
{
System.out.println("Not a leap year");
}
}

You might also like