Code:
class Test{
	public static void main(String[] args){
		int [] num = {6,4,3,5,7};
	
	for(int j = 0; j < num.length; j++){
			for(int i = 0; i < num.length-1; i++){
				if(num[i]+num[i+j]==10){
					System.out.println(num[i]);
					System.out.println(num[i+j]);
				}
			 }
		}
	}//end main
}//end class
//output when printed above
5
5
6
4
3
7
//error
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 5
at Test.main(Test.java:14)

Problem
I am trying to go through the array and print all the two digits which add up to 10. In the answer above show 5, but 5 should be part of the answer, what might the problem be?

Last edited by shabbir; 24Mar2008 at 12:52.. Reason: Code block