Logo 
Search:

Java Articles

Submit Article
Home » Articles » Java » Homework HelpRSS Feeds

Program to read the table elements into a two-dimensional array temperature

Posted By: Easy Tutor     Category: Java     Views: 5527

Write a program to read the table elements into a two-dimensional array temperature and to find the city and day corresponding to

a)the highest temperature and
b)the lowest temperature

Code for Program to read the table elements into a two-dimensional array temperature in Java

import java.io.*;

class  CityTemp
{
    publicstaticvoid main(String args[]) 
    {
            String str;
            double temp[][]=newdouble[11][32];
            double HighestCityTemp[]=newdouble[11];
            double LowestCityTemp[]=newdouble[11];

             HighestCityTemp[0]=0.0;
             LowestCityTemp[0]=0.0;

            try{
                BufferedReader obj = new BufferedReader(new InputStreamReader(System.in));
                System.out.println("\n=====Finding TOP 10 cities higest and lowest temperature=====\n\n");
                for(int i=1;i<=10;i++)
                {
                            System.out.println("\n\nCITY   :   "+i);
                            for(int j=1;j<=31;j++)
                            {
                                 System.out.print("Temperature on Day : "+j+" For city : "+i+" is : ");
                                 System.out.flush();
                                 str=obj.readLine();
                                 temp[i][j]=Double.parseDouble(str);

                                 if( j==1)                 //Intialization
                                 {
                                      HighestCityTemp[i]=temp[i][j];
                                      LowestCityTemp[i]=temp[i][j];
                                }

                                 if(temp[i][j] > HighestCityTemp[i])
                                 {
                                       HighestCityTemp[i]=temp[i][j];
                                }

                                if(temp[i][j] < LowestCityTemp[i])
                                {
                                     LowestCityTemp[i]=temp[i][j];
                                }

                            }
                        }
                    }
                catch(Exception e)    {}

                        for(int i=1;i<=10;i++)
                        {
                                System.out.println("\n\nHIGHEST TEMPERATURE FOR CITY "+i+"  is  "+HighestCityTemp[i]);
                                System.out.println("LOWEST TEMPERATURE FOR CITY "+i+"  is  "+LowestCityTemp[i]);
                                System.out.println();
                        }
    }
}
  
Share: 



Easy Tutor
Easy Tutor author of Program to read the table elements into a two-dimensional array temperature is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!