# JAVA DIMENSIONAL ARRAYS

Page 1 of 1

## 1 Replies - 5307 Views - Last Post: 08 December 2009 - 12:51 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=144254&amp;s=ad66af438644aca9dd5413b803ffec99&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 le_feu_et_glace

Reputation: 0
• Posts: 6
• Joined: 24-November 09

# JAVA DIMENSIONAL ARRAYS

Posted 08 December 2009 - 11:36 AM

HI WELL IM HAVING TROUBLE DOING THIS PROGRAM AND IM FRUSTRATED CAN SOMEONE HELP ME PLEASE

THIS IS WHAT THE PROGRAM SAYS "Write a program that uses a two-dimensional arra to store the highest and lowest temperatures for each month of the year.The program should output the average high , average low and highest and lowest temperatures of the year. Your program will include the following methods:

a. Method getData: this method read and stores the data in the two-dimensional array
b. Method averageHigh: this method calculates and returns the average high temp of the year
c. Method averageLow: this method calculates and returns the average low temp of the year
d. Method indexHighTemp: this method returns the index of the highest temperature in the
array
e. Method indexLowTemp: this method returns the index of the lowest temperature in the array

this is what i have
```
import java.text.*;
import java.math.*;

public static void main(String[] args)
{
Statistics unc = new Statistics();

double[][] calendarTemps = new double[2][12];
int i, j, temp = 0;

Scanner keyboard = new Scanner(System.in);
<strong class="highlight">for</strong> (i = 0; i < calendarTemps.length; i++)
{
<strong class="highlight">for</strong> (j = 0; j < calendarTemps[i].length; j++)
{
Exception exp = null;		 					try{
exp = null;
System.out.println("Please input high temperature " +  (i + 1) + " ");
temp = keyboard.nextInt();
System.out.println("Please input low  temperature " +  (j + 1) + " ");
temp = keyboard.nextInt();
calendarTemps[i][j] = temp;
}catch(Exception e){exp = e;}
} while(calendarTemps[i][j] == null || exp != null);
}
double avgHTemp = unc.averageHigh(calendarTemps);
double avgLTemp = unc.averageLow(calendarTemps);

System.out.println("Average high temperatures <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight>the</strong></vb_highlight> <strong class="highlight">year</strong> is: " + avgHTemp);
System.out.println("Average low temperatures <strong class="highlight">of</strong> <strong class="highlight"><vb_highlight>the</strong></vb_highlight> <strong class="highlight">year</strong> is: " + avgLTemp);

}
}

public class Statistics
{
int avgLTemp = 0;
int higHTemp;
int loWTemp;

public int getData()
{
return 0;
}

public double averageHigh(double[][] avgHigh)
{

int i = 0;
double sumHTemp = 0;
double avgHTemp = 0;

<strong class="highlight">for</strong> (i=0; i < avgHigh.length; i++)
{
sumHTemp = sumHTemp + avgHigh[0][i];
}
avgHTemp = (sumHTemp/avgHigh.length);
return avgHTemp;
}

public double averageLow(double[][] avgLow)
{

int i = 0;
double sumLTemp = 0;
double avgLTemp = 0;

<strong class="highlight">for</strong> (i=0; i < avgLow.length; i++)
{
sumLTemp += avgLow[1][i];
}
avgLTemp = (sumLTemp/avgLow.length);
return avgLTemp;
}

}

```

Is This A Good Question/Topic? 0

## Replies To: JAVA DIMENSIONAL ARRAYS

### #2 erik.price

• D.I.C Lover

Reputation: 485
• Posts: 2,690
• Joined: 18-December 08

## Re: JAVA DIMENSIONAL ARRAYS

Posted 08 December 2009 - 12:51 PM

So what problems are you having? You need to let us know in order for us to help you.

Also, CAPS LOCK DOES NOT HELP

I'm not sure if this is a bug on DIC or not but <strong class="highlight">for</strong> seems to indicate you just copy-pasted this from a website?