Java Programs
Java Programs
}
2) Write a Java Program to accept principal,number of years and rate of
interest and Calculate Simple Interest (Use the formula pnr/100)
//Program to calculate the Simple Interest
import java.util.Scanner;
public class SimpleInterest {
}
3) Write a program to accept perpendicular and base of a right
angled triangle.Calculate and display hypotenuse, area and parameter
of the triangle
//Program to program to accept perpendicular and base of a right
angled triangle.Calculate and display hypotenuse, area and parameter
of the triangle
import java.util.Scanner;
public class Triangle
{
public static void main(String str[])
{
int p,b;
double h,area,per;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the perpendicular:");
p=sc.nextInt();
h=Math.sqrt(p*p+b*b);
area=1.0/2.0*p*b;
per=(p+b+h);
import java.util.Scanner;
public class Discount
{
public static void main(String str[])
{
int r1=15,r2=10,c,p;
double d1,d2,m=0,n=0;
Scanner sc=new Scanner(System.in);
System.out.println("Enter the price of Laptop:");
c=sc.nextInt();
System.out.println("Enter the price of Computer:");
p=sc.nextInt();
d1=(double)r1/100*c;
d2=(double)r2/100*p;
m=c-d1;
n=p-d2;
System.out.println("Price of Laptop after discount:"+m);
System.out.println("Price of Printer after discount:"+n);
}
}
5) Write a program in Java to accept the number of days and display the
result after converting into number of years, number of months and
the remaining number of days
Note: Accept n(number of days)= 789 and check for the output
6) Write a class with name employee and basic as its data member.
Find the gross_pay of an employee for the following allowances and
deduction.
Use meaningful variables
Dearness Allowance=25% of Basic Pay (da)
House Rent Allowance=15% of Basic Pay (hra)
Provident Fund=8.33% of Basic Pay (pf)
Net Pay=Basic Pay + Dearness Allowance + House Rent Allowance(np)
Gross Pay=Net Pay – Provident Fund (gp)
(Note: Please don’t use lengthy variable names
Caution: Use underscore for separating variable names and avoid white
spaces)