You are on page 1of 3

Solutions to Unsolved Java Programs:

Question 1:

Write a program to input a 4-digit number Divide it into two equal halves and find their

sum.

Sample input:

Enter a 4-digit number = 1234

Sample output:
First half = 12

Second half = 34

Sum of two equal halves = 46

import java.util.*;

class Equal
{
public static void main (String ar[])
{
int n, f, l, s;
Scanner sc = new Scanner (System.in);
System.out.println(“Enter a 4-digit number”);
n = sc.nextInt( );
f = n / 100;
l = n % 100;
s = f + l;
System.out.println(“First Half =”+f);
System.out.println(“Second Half =”+l);
System.out.println(“Sum of two equal halves =”+s);
}
}
Question 2.

Write a program by using class 'Employee' to accept Basic Pay of an employee.


Calculate the allowances/deductions as given below.

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

Finally, find and print the Gross and Net pay.


Gross Pay = Basic Pay + Dearness Allowance + House Rent Allowance
Net Pay = Gross Pay - Provident Fund

import java.util.Scanner;
class Employee
{
public static void main(String args[])
{
Scanner in = new Scanner(System.in);
System.out.print("Enter Basic Pay: ");
double bp = in.nextDouble();
double da = 0.3 * bp;
double hra = 0.15 * bp;
double pf = 0.125 * bp;
double gp = bp + da + hra;
double np = gp - pf;
System.out.println("Gross Pay = " + gp);
System.out.println("Net Pay = " + np);
}
}
Question 3.

A shopkeeper offers 10% discount on the printed price of a Digital Camera. However,
a customer has to pay 6% GST on the remaining amount. Write a program in Java to
calculate the amount to be paid by the customer taking printed price as an input.

import java.util.Scanner;

class CameraPrice

public static void main(String args[])

Scanner in = new Scanner(System.in);

System.out.println("Enter printed price of Digital Camera:");

double mrp = in.nextDouble();

double disc = mrp * 10 / 100.0;

double price = mrp - disc;

double gst = price * 6 / 100.0;

price = price + gst;

System.out.println("Amount to be paid: " + price);

You might also like