0% found this document useful (0 votes)
5 views

Practical Assignment IX

The document contains a series of Java programming exercises that cover various topics such as calculating the area and perimeter of a square, performing arithmetic operations on numbers, calculating monthly income based on attendance, converting temperatures, computing GST, evaluating mathematical expressions, and determining leap years. Each exercise includes a Java code snippet that demonstrates the solution. The exercises are designed to help learners practice their programming skills in Java.

Uploaded by

cmchatterjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Practical Assignment IX

The document contains a series of Java programming exercises that cover various topics such as calculating the area and perimeter of a square, performing arithmetic operations on numbers, calculating monthly income based on attendance, converting temperatures, computing GST, evaluating mathematical expressions, and determining leap years. Each exercise includes a Java code snippet that demonstrates the solution. The exercises are designed to help learners practice their programming skills in Java.

Uploaded by

cmchatterjee
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

1. Write a program in Java to find the area, perimeter, and diagonal of a square.

Display
the output of the program by taking the side of a square as 25.

Answer:

public class Square{


public static void main(String args[])
{
int s,ar=0,p=0;
double d=0.0;
s=25;
ar=s*s;
p=4*s;
d=Math.sqrt(2)*s;
System.out.println("The Area of square= "+ar);
System.out.println("The Perimeter of square= "+p);
System.out.println("The diagonal of square= "+d);
}
}

2. Write a program to display


-Sum of two Numbers.
-Difference of two Numbers.
-Product of two Numbers.
When numbers are 25 and 7.

Answer:

public class Result


{
public static void main(String args[])
{
int a=25, b=7, sum , diff, pro;
sum=a+b;
diff=a-b;
pro=a*b;
System.out.println("The Numbers are 25 and 7");
System.out.println("The sum of two numbers = "+sum);
System.out.println("The differece of two numbers = "+diff);
System.out.println("The pro of two numbers = "+pro);
}
}

3. A person is paid ₹350 for each day he works and fined ₹309 for each day he remains
absent. Write a program to calculate and display his monthly income if he is present
for 25 days and remains absent for 5 days.

Answer:

public class Salary_Calc {


public static void main(String args[]) {
int sal_perday=350;
int day_present=25;
int day_abst=5;
int fine=30;
int total_sal=(sal_perday*day_present)+((sal_perday - fine)*day_abst);
System.out.println("The monthly income is :"+total_sal);
}
}
4. In a competitive examination, there were 150 questions. One candidate got 80%
correct and the other candidate got 72% correct. Write a program to calculate and
display the correct answers each candidate got.
Answer:

public class Qest

public static void main(String args[])


{

double que=150;

double candidate1=que*0.72;

double candidate2=que*0.8;

System.out.println("The First Candidate got: "+candidate1+" correct answers");

System.out.println("The First Candidate got: "+candidate2=" correct answers");

}
}

5. The normal temperature of human body is 98.6 degree F. Write a program to convert
the temperature into degree Celcius and display the output.
𝑐 𝑓+32
Hint: =
5 9
Answer:

public class TemperatureConverter


{
public static void main(String[] args)
{
double fahrenheit = 98.6;
double celsius = (fahrenheit - 32) * 5.0 / 9.0;
System.out.println("The normal human body temperature in Celsius is: " + celsius);
}
}
6. A shopkeeper sells an article for ₹ 10000. If the rate of tax under GST is 10%,
calculate and display the tax and the amount paid by the customer.
Answer:
class GST
{public static void main (String args[])
{
int pr=10000;
double gst,amt;
gst=pr*10.0/100.0;
amt=pr+gst;
System.out.println("GST = "+gst);
System.out.println("Amount to pay = "+amt);
}
}

7. Write a program to find and display the value of the given expression:
𝑥+3 2𝑥+5
− ; taking the value of x = 5;
6 3
Answer:
public class Exp1
{
public static void main(String args[]) {
int x = 5;
double value = ((x + 3) / 6.0) - ((2 * x + 5) / 3.0);
System.out.println("Result = " + value);
}
}
8. Write a program using class “Employee’ , while an employee's basic pay is 15000/-.
Calculate the allowances/deductions as given below.
Finally, find and display the Gross and Net pay.
Allowance/Deduction Rate
Dearness Allowance (DA) : 30% of Basic Pay
House Rent Allowance (HRA) : 15% of Basic Pay
Provident Fund (PF) : 12.5% of Basic Pay
Gross Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Net Pay = Gross Pay – Provident Fund
Answer:
public class Employee {
public static void main(String args[]) {
double bp = 15000;
System.out.println("Basic Pay: "+bp);
double da = 0.3 * bp; // DA = 30% of Basic Pay
double hra = 0.15 * bp; // HRA = 15% of Basic Pay
double pf = 0.125 * bp; // PF = 12.5% of Basic Pay

double gp = bp + da + hra; // Gross Pay = Basic Pay + DA + HRA


double np = gp - pf; // Net Pay = Gross Pay - PF

System.out.println("Gross Pay = " + gp);


System.out.println("Net Pay = " + np);
}
}
9. Write a Java program to find out the year 2025 was a leap year or not.
Note:-If the year variable is divisible by 400 or is it divisible by 4 but not 100.
Then Print it’s a Leap Year if true, Print it’s not a Leap year otherwise.
Answer:
public class Leap
{
public static void main (String[]args)
{
int year = 2025;

if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0))


System.out.println (year + " is a Leap Year");
else
System.out.println (year + " is not a Leap Year");
}
}

10. Write a program to find out whether the given value if num is an ODD number or an
EVEN number.
Num=4578;
Answer:

public class EvenOdd {


public static void main(String[] args) {
int num= 4578;
System.out.println("The given number is : "+num);

if(num % 2 == 0)
System.out.println(num + " is even");
else
System.out.println(num + " is odd");
}
}

You might also like