I really wanted to combine my two arrays and I really do not know what is wrong with my code it keeps giving me this results:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: 20 at javaDay3.ArrayExpanding.main(ArrayExpanding.java:17) The results I want to view is :
0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 Please help me to find what is wrong with my code: I wanted to combine the two arrays manually using loops
package javaDay3; public class ArrayExpanding { public static void main(String[] args) { int ages [] = {0,1,2,3,4,5,6,7,8,9}; // my first array for( int i = 0; i < ages.length; i++) { int temp [] = new int [20];// my bigger and 2nd array for(int ix = 0; ix < temp.length; ix++) { for(int ixx = 0; ixx <= temp.length; ixx++) { temp [0] = ages [0] ; System.out.println(temp[ixx]); } } } } } should I add or remove something please help me I am using Eclipse and taking Java
ages[]totemp[]?ixx <= temp.lengthtoixx < temp.length. There it jumps out of bounds. No clue why that loop is even there, because you have 2 loops with the same condition.