Java examples for Language Basics:Array
Create array and assign to another array
public class Main { public static void main(String[] arguments) { int[] myArray = { 1_900_000, 1_700_000, 1_700_000 }; int[] my = new int[myArray.length]; int[] total = new int[myArray.length]; int average; my[0] = 1_900_000;//from ww w.ja v a2 s . c om my[1] = 1_800_000; my[2] = 1_750_000; total[0] = myArray[0] + my[0]; total[1] = myArray[1] + my[1]; total[2] = myArray[2] + my[2]; average = (total[0] + total[1] + total[2]) / 3; System.out.print("2009 production: "); System.out.format("%,d%n", total[0]); System.out.print("2010 production: "); System.out.format("%,d%n", total[1]); System.out.print("2011 production: "); System.out.format("%,d%n", total[2]); System.out.print("Average production: "); System.out.format("%,d%n", average); } }