0% found this document useful (0 votes)
3 views4 pages

II

The document contains a series of Java programming exercises that cover various topics such as mathematical calculations, salary computation, discount applications, value swapping, temperature conversion, eligibility checks based on marks, and compound interest calculations. Each exercise includes a brief description and a corresponding Java code implementation. The programs demonstrate fundamental programming concepts and operations in Java.

Uploaded by

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

II

The document contains a series of Java programming exercises that cover various topics such as mathematical calculations, salary computation, discount applications, value swapping, temperature conversion, eligibility checks based on marks, and compound interest calculations. Each exercise includes a brief description and a corresponding Java code implementation. The programs demonstrate fundamental programming concepts and operations in Java.

Uploaded by

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

II.

UNSOLVED PROGRAMS:

1. Write a program to calculate and display the value of the given expression:
2 2
a + b , when a=20, b=15
a−b
class solve

public static void main(String args[])

int a=20, b=15, c=0;

c= (a*a + b*b)/(a-b);

System.out.println("Answer:" + c);

2. Write a program to calculate the gross salary of an employee when:

Basic salary = ₹8600

DA = 20% of Basic Salary

HRA = 10% of Basic Salary

CTA = 12% of Basic Salary

Gross Salary = (Salary + DA + HRA + CTA)

Display the basic and gross salary.

public class salary {

public static void main(String args[]) {

int bs = 8600;

double DA = 0.2 * bs;

double HRA = 0.1 * bs;

double CTA = 0.12 * bs;

double gs = bs + DA + HRA + CTA;

System.out.println("Basic Salary:" + bs);

System.out.println("Gross Salary:" + gs);

}
3. A shopkeeper announces two successive discounts 20% and 10% on purchasing of goods at the
marked price. Write a Java program to input marked price using Scanner class. Calculate and display
the selling price of the article.

public class Price {

public static void main(String[] args) {

int mP = 2000;

double d1 = 0.20 * mP;

double dP1 = mP - d1;

double d2 = 0.10 * dP1;

double dP2 = dP1 - d2;

double sp = dP2;

System.out.println("Selling Price after 20% and 10% discounts: " + sp);

4. Write a Java program to input two unequal numbers. Display the numbers after swapping their
values in the variables, without using a third variable.

public class Variable {

public static void main(String[] args) {

int num1 = 23, num2 = 56;

System.out.println("Before swapping:");

System.out.println("First number: " + num1);

System.out.println("Second number: " + num2);

num1 = num1 + num2;

num2 = num1 - num2;

num1 = num1 - num2;

System.out.println("After swapping:");

System.out.println("First number: " + num1);

System.out.println("Second number: " + num2);

}
5. Write a program to input the temperature in Celsius and then convert into Fahrenheit. If the
temperature in Fahrenheit is more than 98.6°F then display “Fever” otherwise “Normal”.

public class Convert {

public static void main(String[] args) {

double cel = 104 ;

double fah = (cel * 9/5) + 32;

System.out.println("Temperature in Fahrenheit: " + fah);

if (fah > 98.6) {

System.out.println("Fever");

} else {

System.out.println("Normal");

6. Write a program to accept the marks, obtained in five different subjects(English, Physics,
Chemistry, Biology, Maths) by a student and find the average marks. If the average is 80 or more,
then display he/she eligible to get “Computer Science”, otherwise “Biology”.

public class Eligibility {

public static void main(String[] args) {

int engMarks = 78;

int phyMarks = 82;

int chemMarks = 89;

int bioMarks = 80;

int mathsMarks = 92;

int total = engMarks + phyMarks + chemMarks + bioMarks + mathsMarks;

double avg = total/3;

if (avg >= 80) {

System.out.println("Eligible for Computer Science");

} else {

System.out.println("Eligible for Biology");

}
}

7. Write a program to accept the values for the principal, rate and time. Calculate and display the
interest accumulated for the first , second and the third year compounded annually.

public class CompoundInterest {

public static void main(int P,int t) {

double r = 10/100;

double I1 = P * Math.pow(1 + r, t) - P;

System.out.println("Interest accumulated in the first year: " + I1);

double A1 = P + I1;

double I2 = A1 * Math.pow(1 + r, t) - A1;

System.out.println("Interest accumulated in the second year: " + I2);

double A2 = A1 + I2;

double I3 = A2 * Math.pow(1 + r, t) - A2;

System.out.println("Interest accumulated in the third year: " + I3);

You might also like