Structure Query Language, C programming, Java, Servlet, Jsp, Unix

Sunday 15 July 2012

Write a class called Statistics, which has a static method called average, which takes a onedimensional array for double type, as parameter, and prints the average for the values in the array. Now write a class with the main method, which creates a two-dimensional array for the four weeks of a month, containing minimum temperatures for the days of the week(an array of 4 by 7), and uses the average method of the Statistics class to compute and print the average temperatures for the four weeks.


[ temperature.java ]
import java.io.*;
class Statistics
{
public static double average(double intdouble[])
{
int i=0;
double sum=0;
for(i=0;i<intdouble.length;i++)
{
sum+=intdouble[i];
}
return sum/intdouble.length;
}
}
class temperature
{
public static void main(String[] args) throws IOException
{
int i=0,j=0;
double week[][];
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));

week=new double[4][7];
for(i=0;i<4;i++)
{
System.out.println("Week " + (i+1) + " : ");
for(j=0;j<7;j++)
{
System.out.print("Enter Temprature Of Day " + (j+1) + " : ");
week[i][j]=Double.parseDouble(br.readLine());
}
System.out.println("");
}
System.out.println("AVERAGE TEMPRATURE : ");
for(i=0;i<4;i++)
{
System.out.println("WEEK " + (i+1) + " : " + Statistics.average(week[i]));
}
}
}

1 comment:

  1. GoTo Command Prompt(Win + R)

    HOW TO COMPILE
    javac c:\yourdir\temperature.java

    HOW TO EXECUTE
    java c:\yourdir\temperature

    ReplyDelete