You are on page 1of 5

TCS ASPIRE : JAVA ASSIGNMENT NO : 1

1. Write a program to find the difference between sum of the squares and the square of the sums
of n numbers? Sum of the square(n) ,square of sum n
import java.util.Scanner;
import java.lang.String;
class sum
{
public static void main(String args[])
{
float s=0,s2=0;int i;
System.out.println(“enter n value”);
Scanner st=new Scanner(System.in); int n=st.nextInt();
int a[] =new int[n];
for(i=0;i<n;i++)
{a[i]=st.nextInt(); //enter n values
}
for(i=0;i<n;i++)
{
s=s+a[i];
}
float d=(s*s);
for(i=0;i<n;i++)
{s2=s2+((a[i])*(a[i]));}
float f = (d-s2);
System.out.println(f);
System.out.println(“difference between sum of the squares and the square of the sums of
“+n+”numbers is:” +f);
}}
2. Develop a program that accepts the area of a square and will calculate its perimeter.
import java.util.Scanner;
import java.lang.*;
class area
{
public static void main(String args[])
{
System.out.println(“enter area value”);
Scanner st=new Scanner(System.in);
double n=st.nextDouble();
double s=Math.sqrt(n);
double perimeter=4*s;
System.out.println(perimeter);
}
}

} } 5.text.15.out.print(“Enter Number of Working hours: “). System. v=p*r*r*h.out. Every performance costs the theater $20.PI. Assume an hourly rate of $12. double tax=gpay*trate. System.nextDouble(). public class CalculateTax { public static void main (String[] args) { double trate=0.Scanner. double r=st.nextDouble(). System. double hrate=12.*.out.lang. double p=Math.out.println(“Enter Number of Days Worked in a year:”). import java. double h=st.. double netpay=gpay-tax.println(“Volume of cylinder is: “+v).in). Develop the program calculateCylinderVolume. Utopias tax accountants always use programs that compute income taxes even though the tax rate is a solid. plus $.50 per attendee.out. An old-style movie theater has a simple profit program.println(“enter height”).util. System. import java. } } 4. import java. never-changing 15%. double hrs=input.in). Scanner input=new Scanner(System.println(“enter radius value”).3. System. which accepts radius of a cylinder's base disk and its height and computes the volume of the cylinder.nextDouble().*. System. Define the program calculateTax which determines the tax on the gross pay. import java. Develop the program . Define calculateNetPay that determines the net pay of an employee from the number of hours worked. Each customer pays $5 per ticket.nextInt(). double gpay=days*hrs*hrate.*.util. Scanner st=new Scanner(System.out. int days=input.println(“Net Pay is: $”+netpay). class calculateCylinderVolume { public static void main(String args[]) { double v=0.

its length. Develop the program calculateCylinderArea. . import java.out. import java. import java. and the thickness of its wall. which accepts radius of the cylinder's base disk and its height and computes surface area of the cylinder.*. import java.println(“The calculated surface area is: “+surfacearea+” sq m”). It computes the surface area of a pipe. The program accpets three values: the pipes inner radius. Develop the program calculatePipeArea.println(“Enter the height of cylinder(in m) : “). } } 6. int a=s. class calculateTotalProfit { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System.lang.out.calculateTotalProfit that consumes the number of attendees (of a show) and calculates how much income the show earns.Scanner. import java. double percost = 20 . System. import java. double pi=Math. } } 7. class calculateCylinderArea { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System. double profit = (5*a)-(a*attendecost+20).in).5. System. which is an open cylinder. System.println(“Enter the base radius of cylinder(in m): “). double attendecost =0.io.nextDouble(). import java. System.out.*.util. import java.nextInt().println(“The profit for the show is : $”+profit).println(“Enter the number of attendes for show : “).*.out.*.Scanner. System.io.in).util.util.out. double surfacearea=(2*pi*r*(r+h)).io.Scanner. double h=s.nextDouble() .lang.*.PI. double r=s.

println(“Enter the length of pipe(in m) : “).util. System.PI.println(“Enter the width of the river (in m) : “). System. and the Pythagorean Theorem is c2 = a2 + b2. System. double h=(vel*time)/2.println(“Height reached by the rocket (in km) is : ” +(h/1000)). given the width of the river. double g=9. Speed is distance/time.out.Scanner. If the rocket accelerates at a constant rate g.out.out.nextDouble() . Develop the program calculateHeight. double r=s. 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.nextDouble().println(“Enter the inner radius of pipe(in m): “). the boat's speed perpendicular to the river. import java.in). public class calculateHeight { public static void main(String[] args) { System.println(“Enter the time in seconds : “).nextDouble().in). double pi=Math. and the river's speed.in).8. Scanner s=new Scanner(System. public class Distance{ public static void main(String[] args) { Scanner s= new Scanner(System. acc=g.println(“The calculated surface area is: “+surfacearea+” sq m”). } } 9.out.class calculatePipeArea { public static void main(String args[]) throws IOException { Scanner s=new Scanner(System. System. import java. double surfacearea=(2*pi*(r+t)*l). System.out. Develop a program that computes the distance a boat travels across a river. which computes the height that a rocket reaches in a given amount of time.nextDouble() .out. System. . double acc.println(“Enter the thickness of pipe(in m) : “).out. double t=s. double l=s. double time=s. double vel=acc*time.Scanner.util. } } 8.

double m=s. double bspeed=s.util.out. System.nextDouble(). System. double finalbal=p+ad.println(“Enter the annual interest rate in percentage: “). double ad=p*(m/12)*(ir/100). the annual interest rate expressed as a decimal. System. and the number of years.out.double width=s. System.print(“final balance will be “+finalbal). double rspeed=s. double p=s.Scanner. System.nextDouble().sqrt((width*width)+(d*d)). } } .println(“Enter the number of months : “).println(“Enter speed of the boat(in m/s) : “). Total interest is the product of the principal.out.println(“Enter the principal amount : “).nextDouble(). //distance travelled down stream double totald=Math. System. and a number of months will compute the balance at the end of that time.in).println(“The distance travelled by boat(in m): “+totald). double ir=s.nextDouble(). import java. double time=width/bspeed.out. //time to travel to other bank by the boat double d=time*rspeed. public class calculateBalance { public static void main(String[] args) { Scanner s=new Scanner(System.nextDouble(). System.out.out.nextDouble(). a simple annual interest rate. Assume that no additional deposits or withdrawals are made and that a month is 1/12 of a year.println(“Enter speed of river (in m/s) : “). } } 10. Develop a program that accepts an initial amount of money (called the principal).out.