Hi..

this is my code:

import java.util.Scanner;

public class Arrays {
	//private variables
	private int[][] list = new int [12][2];
	private int highest;
	private int lowest;
	
	//public functions
	Arrays(){
		highest = 55;
		lowest = 5;
		list = new int[12][2];
		
	}
	public int getData(){
		Scanner input = new Scanner(System.in);
		
		for ( int i=1; i<13; i++ )
		{
			System.out.printf("%s",i);
			
			for ( int j=0; j<2; j++)
			{
				list[i][j]= input.nextInt();
				
			}
		}
		
		return 0;
	
	}
	public float averageHigh(){
		
		int total = 0;
		float average;
		
		for ( int i=1; i<=12; i++){
			total = total + list[i][0];
		}
		
		average = total/12;
		
		return average;
		
	}
	public float averageLow(){
		
		int total = 0;
		float average;
		
		for ( int i=1; i<=12; i++){
			total = total + list[i][1];
		}
		
		average = total/12;
		
		return average;
		
	}
	public int indexHighTemp(){
		
		int highest;
		highest = list[1][0];
		int i;
		for ( i=2; i<=12; i++){
			if ( list[i][0]> highest)
				highest = list[i][0];
			
		}
			
		return i;
		
	}
	
	public int findhighest(){
		
		highest = list[1][0];
		
		for ( int i=2; i<=12; i++){
			if  ( list[i][0] > highest )
				highest = list[i][0];
		}
		
		return highest;
		
	}
	
	public int findlowest(){
		
		lowest = list[1][1];
		
		for ( int i=2; i<=12; i++){
			if ( list[i][1] < lowest )
				lowest = list[i][1];
			
		}
		
		return lowest;
			
	}
	
	
};

and this is the main:

public class Arraystest {
	
	public static void main( String[] args ){
	
	Arrays arraylist = new Arrays();
	
	System.out.println("Please Enter the highest and lowest " +
		"temperature of the corresponding month: ");
	
	//get data from the user
	System.out.printf("\n%s%12s%12s\n","month","Highest","Lowest");
	arraylist.getData();
	
	//printing the average hight & average low
	System.out.printf("\n\nThe average highest temperature" +
			" is: \n%d",arraylist.averageHigh());
	System.out.printf("\nThe average lowest temperature" +
			" is: \n%d",arraylist.averageLow());
	
	//print the highest temp. & lowest temp.
	System.out.printf("\n\nThe highest temperatur is: %d\n",arraylist.findhighest());
	System.out.printf("\nThe lowest temperatur is: %d\n",arraylist.findlowest());
	
	
	}
	
}

my question is:
when I enter the 12th month elementes it shows me an error which is:

12Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 12
at Arrays.getData(Arrays.java:25)
at Arraystest.main(Arraystest.java:13)

please help me

public static void main( String[] args )

Um..... if this is a Java question you may want to post it in the Java (not C++) forums.

thanks..

I noticed my mistake and solved it..

thanks alot.

Um..... if this is a Java question you may want to post it in the Java (not C++) forums.

Please use the "Flag Bad Post" button to help us tackle such things. Making a post saying "it's not the correct forum" might lead to double posting by the OP.

thanks..

i will consider that next time..^^..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.