You are on page 1of 13

# JAVA ASSIGNMENT 1 1.

Write a program to find the difference between sum of the squares and the square of the sums of n numbers? Program: import java.io.*; import java.util.*; class DiffSumSqu { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System.in); System.out.println("Enter the value of n: "); int n=s.nextInt(); int SumSqua=((n^3)/3)+((n^2)/2)+(n/6); int sum = 0; for(int i = n;i>=0;i--) { sum = sum + i; } int SquaSum = sum * sum; diff = SumSqua-SquaSum; System.out.println("Difference between sum of the squares and the square of the sum of given "+n); System.out.print(" numbers is : "+diff); System.out.println(""); }

out. System. Program: import java.in).out.} Output: Enter the value of n: 5 Difference between sum of the squares and the square of the sum of given 5 numbers is : 3328 2) Develop a program that accepts the area of a square and will calculate its perimeter. class AreaPeri { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System.sqrt(Area).*. } } . System. System.out.nextDouble().util.io.println("Area of Square : ").print("so the Perimeter of the Square : "+p). double Area=s.*.println(""). import java. double Perimeter=4*Math.

println(""). System.println("Enter the radius : "). } .util.nextDouble().out.out.nextDouble().println("Volume of the cylinder is : " + vol). double vol=Math. class CalculateCylinderVolume { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System.*. System. import java. System. System. which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.out.println("Enter the height : ").in).out.io.PI*rad*rad*ht.. double rad=s.*. double ht=s.Output: Area of Square : 16 so the Perimeter of the Square : 16. Program: import java.0 3)Develop the program calculateCylinderVolume.

out. System. of working hours in a day : ").*. Define the program calculateTax which determines the tax on the gross pay.println("Enter the no. class Utopias { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System. System.69911184307752 4)Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid.out. of hours worked in over time : ").out. System. import java.util. Program: import java.*.} Output : Enter the radius : 2 Enter the height : 3 Volume of the cylinder is : 37. Assume an hourly rate of \$12.io.nextInt(). int days=s.println("Days worked by employer in a year : "). .nextInt(). int hours=s. never-changing 15%.println("Enter the no. Define calculateNetPay that determines the net pay of an employee from the number of hours worked.in).

println("").15.println("Enter the no. of hours worked in over time : 50 Enter the no.out. of hours took leave : 10 Gross Pay (in \$) : 28800. of working hours in a day : 8 Enter the no. int l=s.0 Net Pay (in \$) : 29280.int ot=s.nextInt().println("Tax (in \$) : "+tax).out. double gross=((days*hours)+ot-l)*12. System.out. System. double net=gross-tax.0 . System.println("Gross Pay (in \$) : "+gross). double tax= gross*0.println("Net Pay (in \$) : "+net). System. System.out.out. of hours took leave : ").nextInt(). } } Output : Days worked by employer in a year : 300 Enter the no.

*. Each customer pays \$5 per ticket.5)).nextInt(). double profit = (n*5)-(20+(n*0.Tax (in \$) : 4320.0 . System. of attendees of a show : 100 Total Profit of the theater per show (in \$) is : 430. System.io. import java. of attendees of a show : ").out.util. int n=s. Develop the program calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much income the show earns Program: import java. class calculateTotalProfit { public static void main (String args[]) throws IOException { Scanner s = new Scanner(System.*.in).out.0 5)An old-style movie theater has a simple profit program.50 per attendee. Every performance costs the theater \$20.println("Enter the no.out.println(""). plus \$. } } Output : Enter the no. System.println("Total Profit of the theater per show (in \$) is : " + profit).