import java.util.Arrays; public class SwapHalves { public static void main(String[] args) { int[] elements = { 1, 4, 9, 7, 3, 2, 5, 11, 0, 9 }; int j = elements.length / 2; for(int i = 0; i < (elements.length / 2); i++) { int saved = elements[i]; elements[i] = elements[j]; elements[j] = saved; j++; } System.out.println(Arrays.toString(elements)); } }
two dimension array
double reg1 = prices[0][1]; for (int i = 0; i < prices.length; i++) { for (j = 0; j < prices[0].length; j++) { System.out.printf("%10.3f", prices[i][j]); } System.out.println(); }