Wednesday, November 24, 2010

Java Prog 1

// calculating the difference between the sum of squares of the number and the square of the sum of the number
import java.io.*;
class calcSquares
{
  public static void main( String args[]) throws Exception
  {
    System.out.println("Enter the value of n");
    DataInputStream dis= new DataInputStream(System.in);
    String str=dis.readLine();
    int n=Integer.parseInt(str);
    int sqr[]= new int[30];
    int number[]= new int[30];
    int i;
    int sumSquares=0;
    int sumNum=0;
    for(i=0;i<n;i++)
    {
      System.out.println(" Enter the value for " + i + "number");
      DataInputStream dis1= new DataInputStream(System.in);
    String str1=dis.readLine();
    number[i]=Integer.parseInt(str1);
    sqr[i]=(number[i]*number[i]);
    }
    for(i=0;i<n;i++)
    {
      System.out.println(sqr[i]);
      sumSquares=sumSquares+sqr[i];
      sumNum=sumNum+number[i];
    }
    System.out.println("The difference is :"+((sumNum*sumNum)-sumSquares));
    System.out.println((sumNum*sumNum));
    System.out.println(sumSquares);
  
  }
}
      //Calculate Cylinder Volume
import java.io.*;
class cylinderVolume
{
  public static void main( String args[]) throws Exception
  {
    double pi = 3.14;
    System.out.println("Enter the Cylinder's height and radius ");
    DataInputStream dis= new DataInputStream(System.in);
    String str=dis.readLine();
    int height = Integer.parseInt(str);
    DataInputStream dis1= new DataInputStream(System.in);
    String str1=dis1.readLine();
    int radius = Integer.parseInt(str1);
    double volume =(pi*(radius*radius)*height);
    System.out.println("The Volume of the Cylinder is " + volume);
  }
}
//Calculate Cylinder Volume
import java.io.*;
class cylinderVolume
{
  public static void main( String args[]) throws Exception
  {
    double pi = 3.14;
    System.out.println("Enter the Cylinder's height and radius ");
    DataInputStream dis= new DataInputStream(System.in);
    String str=dis.readLine();
    int height = Integer.parseInt(str);
    DataInputStream dis1= new DataInputStream(System.in);
    String str1=dis1.readLine();
    int radius = Integer.parseInt(str1);
    double volume =(pi*(radius*radius)*height);
    System.out.println("The Volume of the Cylinder is " + volume);
  }
}

No comments:

Post a Comment