# 1.

Write a program to find the difference between sum of the squares and the squ are of the sums of n numbers ? Program: import java.io.*; import java.util.Scanner; class Difference { public static void main(String args[]) throwsIOException { Scanner s=new Scanner(System.in); System.out.println("Enter the value of n: "); int n=s.nextInt(); int a[]=new int[n]; int i, sqr, diff, sum=0, add=0; System.out.print("The "+n); System.out.println(" numbers are : "); for(i=0;i<n;i++) { a[i]=s.nextInt(); sum+=(a[i]*a[i]); add+=a[i]; } sqr=add*add; diff=sqr-sum; System.out.println(""); System.out.print("Sum of Squares of given "+n); System.out.println(" numbers is : "+sum); System.out.print("Squares of Sum of given "+n); System.out.println(" numbers is : "+sqr); System.out.println(""); 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 put: Enter the value of n: 4 The 4 numbers are : 2 3 4 5 Sum of Squares of given 4 numbers is : 54 Squares of Sum of given 4 numbers is : 196 Difference between sum of the squares and the square of the sum of given 4 numbers is : 142 ----------------------------------------------------------------------------------------------------2. Develop a program that accepts the area of a square and will calculate its pe rimeter. Program:

nextDouble(). never-changing 15%.println("Enter the height : ").in).061447520093 ------------------------------------------------------------------------------------------------------4. double p=4*Math. import java.println(" ").util. System. System. double a=s.out.import java. .out.println("Volume of the cylinder is : " + vol).out. } } Output: Enter the radius : 12 Enter the height : 13 Volume of the cylinder is : 5881. System..Scanner.PI*rad*rad*ht.out.println("").nextDouble().println("Enter the radius : "). System. System. which accepts radius of a cyli nder's base disk and its height and computes the volume of the cylinder.in).println("Enter the Area: ").out. System. class calculateCylinderVolume { public static void main(String args[]) throwsIOException { Scanner s=new Scanner(System.out.*.print("Perimeter of the Square : "+p). System.sqrt(a).println(" "). double vol=Math.183326093250876 ------------------------------------------------------------------------------------------------------3.util. double rad=s. System.Scanner. public class CalculateSquarePeri { public static void main(String[] args) { Scanner s=new Scanner(System.out. Develop the program calculate CylinderVolume. double ht=s. Program: import java. Utopias tax accountants always use programs that compute income taxes even th ough the tax rate is a solid.io. } } Output: Enter the Area: 23 Perimeter of the square is: 19.nextDouble().out.

of hours worked in over time : "). System.nextInt().nextInt(). of working hours in a day : "). System. int ot=s.out.15. System. Each customer pays \$5 per ticket.out. int d=s. public class calculateTax { public static void main(String[] args) { Scanner s=new Scanner(System. Program: import java. System. of working hours in a day : 6 Enter the no. Every performance costs the theater \$20. System.Scanner. Assume an hourly rate of \$12.println("Net Pay (in \$) : "+net). of working days in the year : "). int h=s. System. An old-style movie theater has a simple profit program.out.in). plus \$.0 Tax (in \$) : 433.Define the program calculateTax which determines the tax on the gross pay.out. double tax= gross*0. int l=s.out. System.println("Enter the no.out. .8 Net Pay (in \$) : 2458. of hours took leave : ").println("Enter the no.out.50 per attendee.nextInt().2 -----------------------------------------------------------------------------------------------------5. } } Output: Days worked by employer in a year : 300 Enter the no. double net=gross-tax.println("Enter the no.println("Gross Pay (in \$) : "+gross).println("").println("Enter the no.util. System. of hours worked in over time : 1 Enter the no. double gross=((d*h)+ot-l)*12. of hours took leave : 1560 Gross Pay (in \$) : 2892.nextInt().println("Tax (in \$) : "+tax). Develop the program calculate TotalProfit that consumes the number of attende es (of a show) and calculates how much income the show earns.out. Define calculateNetPay that determines the net pay of an employee from the nu mber of hours worked.

System. its leng th. } } Output: Enter the no.9555921538758 ------------------------------------------------------------------------------------------------------7.out. of attendees of a show : "). System.out.nextDouble().println(""). of attendees per show : 50 Total Profit of the theater per show (in \$) is : 205.out. System.Scanner.Program: import java.out. It computes the surface area of a pipe .out.println("Total Profit of the theater per show (in \$) is : " + profit) . double ht=s. which accepts radius of the cylin der's base disk and its height and computes surface area of the cylinder.println("Enter the height : "). and the thickness of its . Program: import java. System. double profit = (n*5)-(20+(n*0.out. double area=2*Math. Develop the program calculatePipeArea. Develop the program calculate CylinderArea. System. System.println("Surface Area of the cylinder is : " + area).nextInt(). public class calculateTotalProfit { public static void main(String[] args) { Scanner s = new Scanner(System. The program accpets three values: the pipes inner radius.0 ------------------------------------------------------------------------------------------------------6.out.Scanner. } } Output: Enter the base radius : 12 Enter the height : 13 Surface Area of the cylinder is : 1884. which is an open cylinder. int n=s.util.println("Enter the base radius : ").in).nextDouble().println(""). double rad=s.PI*rad*(rad+ht).in). System. public class calculateCylinderArea { public static void main(String[] args) { Scanner s=new Scanner(System.println("Enter the no.5)).util.

double v=9. double thick=s.out.out.Scanner. public class calculatePipeArea { publicstaticvoid main(String[] args) { Scanner s=newScanner(System. System. } } Output: Enter the inner radius : 13 Enter the length : 20 Enter the thickness : 5 Surface Area of the pipe is : 2261.8*t.println(""). System. System. System. it reaches a speed o f g t in t time units and a height of 1/2 * v * t where v is the speed at t. double len=s.wall.println("").If the rocket accelerates at a constant rate g. public class calculateHeight { public static void main(String[] args) { Scanner s=newScanner(System. } } Output: Enter the time (in seconds) : 300 .Scanner. System.util. which computes the height that a rocket reaches in a given amount of time.util. double rad=s.nextDouble(). program: import java. double height=0.in).nextDouble().946710584651 -----------------------------------------------------------------------------------------------8.5*v*t. double area=2*Math.PI*(rad+thick)*len.println("Enter the time (in seconds) : ").println("Enter the inner radius : "). Program: import java.out. Develop the program calculateHeight.out.nextDouble().out.println("Enter the thickness : ").out.in). double t=s.println("Surface Area of the pipe is : " + area).println("Enter the length : "). System.out.nextDouble(). System. System.println("Height reached (in meters) is : " + height).out.

//distance due to down stream double bd=Math. Speed is distance/time.println("Enter the river's speed (in meter/sec) : "). } } Output: Enter the width of the river (in meters) : 15 Enter the river's speed (in meter/sec) : 200 Enter the boat's speed (in meter/sec) : 250 The distance travelled by boat (in meters) is : 19.sqrt((rw*rw)+(w2*w2)). Program: import java. and the river's speed.nextDouble().util. Develop a program that accepts an initial amount of money (called the princi pal). System.println("The distance travelled by boat (in meters) is : "+bd). System.println("Enter the width of the river (in meters) : "). System.out.0 ----------------------------------------------------------------------------------------------9. public class calculateBalance { public static void main(String[] args) { . Assume that no additional deposits or withdrawals are made and that a month is 1/ 12 of a year. Program: import java. the boat's speed perpendicular to the river.out.out. the annual interest rate express ed as a decimal. a simple annual interest rate.println(""). System. public class BoatDistance{ public static void main(String[] args) { Scanner s= new Scanner(System.Scanner. double rw=s.Height reached (in meters) is : 441000.in). g iven the width of the river. double rs=s. double time=rw/bs. and the number of years. Develop a program that computes the distance a boat travels across a river. and the Pythagorean Theorem is c2 = a2 + b2.nextDouble().nextDouble().209372712298546 -------------------------------------------------------------------------------------------------10.println("Enter the boat's speed (in meter/sec) : "). //time takes to travel from shore to shore straight by the bo at double w2=time*rs.util.Scanner. double bs=s. Total interest is the product of the principal. System.out. and a number of months will compute the balance at the end of that time.out.

println(""). double r=s.out.nextDouble().out.nextDouble().print("Balance after " +(int)m).0 . System. System. double bal=p+si.Scanner s=new Scanner(System.println("Enter the no. double p=s. System.println("Enter the annual interest rate : "). } } Output: Enter the principal amount : 15000 Enter the annual interest rate : 12 Enter the no.nextDouble().out. System.out.println(" month(s) is : "+bal). System.in). of years in months : "). double si=(p*(m/12)*r)/100. double m=s. System. of months : 24 Balance after 24 month(s) is : 18600.out.out.println("Enter the principal amount : ").