You are on page 1of 5

1.

Write a program to find the difference between sum of the squares and the squ
are of the sums of n numbers?

public class diff
{
public static void main(String[] args)
{
diff d=new diff();
int[] a=new int[args.length];
for(int i=0;i<args.length;i++)
{
a[i]=Integer.parseInt(args[i]);
}
int sosq=0;
for(int i=0;i<args.length;i++)
{
sosq=sosq+(a[i]*a[i]);
}
System.out.println("Some of square is "+sosq);
int sqos=0;
for(int i=0;i<args.length;i++)
{
sqos=sqos+a[i];
}
sqos=sqos*sqos;
System.out.println("Some of square is "+sqos);
}
}
2. Develop a program that accepts the area of a square and will calculate its pe
rimeter.
import java.io.*;
class perimeter
{
public static void main(String[] args) throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter area of square");
int area=Integer.parseInt(br.readLine());
System.out.println("Perimeter: "+(4*Math.sqrt(area)));
}
}

3. Develop the program calculateCylinderVolume., which accepts radius of a cylin
der's base disk and
its height and computes the volume of the cylinder.

parseInt(br. Every performance costs the theater $20.println("Volume: "+(Math. class calculateTotalProfit { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.io. Define the program calculateTax which determines the tax on the gross pay.*. import java. Define calculateNetPay that determines the net pay of an employee from the nu mber of hours worked.readLine()). Each customer pays $5 per ticket. System. } } 5.readLine()).50 per attendee. System.PI*r*r*h)). Utopias tax accountants always use programs that compute income taxes even th ough the tax rate is a solid.out.in)).parseInt(br. int h=Integer.println("Enter total no of hours"). Develop the program calculateTotalProfit that consumes the number of attendee s (of a show) and calculates how much income the show earns.println("Enter height").parseInt(br. .out. System. System. System.out.println("Enter radius").*.println("Enter total no of attendees"). int r=Integer. Assume an hourly rate of $12. plus $.io.*.io. never-changing 15%.in)). int h=Integer. An old-style movie theater has a simple profit program.out.readLine()). import java.println("NetPay: "+(12*h-0. System. class volume { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System. class netPay { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.in)).15*(12*h))).out. } } 4. import java.out.

parseInt(br.io. int t=Integer.out.*.println("Volume: "+(2*Math.println("Enter height").out. } } 7. which isan open cylinder.readLine()).PI*r*h)). System. which computes the height that a rocket . class calculatePipeArea { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.println("Enter height"). and the thickness of its wall.5*n)))).io. System. System.readLine()).println("Total Income: "+((5*n)-(20+(0.println("Volume: "+(2*Math.out. } } 8.out.*.in)). System.parseInt(br.readLine()).println("Enter inner radius").parseInt(br. System.int n=Integer.PI*(r+t)*h)).in)). System.out. Develop the program calculateCylinderArea. class calculateCylinderArea { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.println("Enter radius").out. int r=Integer. int h=Integer. It computes the surface area of a pipe . its length. int h=Integer. import java. int r=Integer.parseInt(br.println("Enter thickness").out.out.parseInt(br.readLine()). System. Develop the program calculatePipeArea.readLine()). } } 6.parseInt(br. Develop the program calculateHeight. import java. The program accpets three values: the pipes inner radius. System.readLine()). which accepts radius of the cylind er's base disk and its height and computes surface area of the cylinder.

reaches in a given amount of time. If the rocket accelerates at a constant rate g. Develop a program that accepts an initial amount of money (called the princi pal). int t=Integer.out. System.out. System.parseDouble(br.io.out. System.out.5*g*t*t)+" meters"). import java. x=1+x*x.g-9. a simple annual interest rate. Total interest is the product of the principal. System. x=Math.readLine()).in)). class distance { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System. double x=rs/bs.e.readLine()).parseDouble(br. System.parseInt(br. import java. given the width of the river.out.println("Enter acceleration "). System.println("Enter river speed"). x=1/x.println("Enter boats speed"). System.sqrt(x).*. an d the river's speed. and a number of months will compute the balanc e at the end of that time. the boat's speed perpendicular to the river. it reaches a speed of g ·t in t time units and a height of 1/2 * v * t where v is the speed at t. double w=Double. class calculateHeight { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System. Double g=Double.parseDouble(br.io. Assume that no additional deposits or withdrawals are made and that a month i s 1/12 of a year.readLine()).println("Enter width of river"). Develop a program that computes the distance a boat travels across a river. } } 10.readLine()). the annual interest rate expr . and the Pythagorean Theorem is c2 = a2 + b2.//assume that g is resul tant acceleration i. Speed is distance/time.println("Height: "+(0.in)).8 } } 9.out.println("Enter time in seconds "). double rs=Double. double bs=Double.*.out.parseDouble(br.readLine()).println("Distance: "+(w/x)).

} } .println("Enter Principal"). double r=Double.println("Enter Rate").readLine()).readLine()).out.01*(p*r*t))).parseInt(br.println("Enter months"). System. Double t=Double.parseDouble(br.essed as a decimal. System.in)).parseDouble(br. t=t/12.println("Interest: "+(0.out. int p=Integer.readLine()). System.*. class SimpleInterest { public static void main(String[] args) throws IOException { BufferedReader br=new BufferedReader(new InputStreamReader(System.out. import java.out. and the number of years.io. System.