// // P.61 TestArrays1.java // import java.util.Scanner; public class TestArrays1 { public static void main(String[] args) { Scanner input = new Scanner(System.in); int[] myArray = new int[20]; // Q: declare 30 string array youArray? String[] youArray = new String[30]; // Set the first integer to 12? myArray[0] = 12; // Q: set the second integer to 7, and the last 100? myArray[1] = 7; myArray[19] = 100; // Q: set the second string to "VWC", the last "UVA"? youArray[1] = "VWC"; youArray[29] = "UVA"; // out the first integer to the monitor? System.out.println("1st integer = " + myArray[0]); // Q: out the last string to the monitor? System.out.println("Last string = " + youArray[29]); // set the 3rd integer as the sum of the first two? myArray[2] = myArray[0] + myArray[1]; // Q: set the 4th one as the sum of the first and the last? myArray[3] = myArray[0] + myArray[19]; // set all integers to 0s for(int i=0; i<20; i++) myArray[i] = 0; // out all the integers to the monitor? for(int i=0; i<20; i++) System.out.print(myArray[i] + " "); System.out.println("\n\n"); // Q: set all strings to "USA"? for(int i=0; i<30; i++) youArray[i] = "USA"; // Q: out all the strins to the monitor? for(int i=0; i<30; i++) System.out.print(youArray[i] + " "); // input the first integer from the keyboard? System.out.print("\n\nInput the 1st integer: "); myArray[0] = input.nextInt(); // debug System.out.println("1st integer = " + myArray[0]); String dummy = input.nextLine(); // Q: input the last string from the keyboard? System.out.print("\n\nInput the last string: "); youArray[29] = input.nextLine(); // debug System.out.println("last string = " + youArray[29]); System.out.println("\n\nDone.\n\n"); } }