Week1Mock1MCQ32

Run Settings
LanguageJava
Language Version
Run Command
// import java.util.*; public class Main { public static void main(String[] args) { // Harbor, Week 1, Mock 1, PR_PracticeTest_1.pdf // AP CS A // MCQ 32 int nums[][] = {{1, 2, 3, 4, 5}, {6, 7, 8, 9, 10}}; // I. for (int r = 0; r < nums.length; r++) { for (int c = 0; c < nums[0].length; c++) { System.out.print(nums[r][c] + " "); } System.out.print("\n"); } System.out.println(); // II. for (int[] row: nums) { for (int col: row) { System.out.print (col + " "); } System.out.println(""); } /* // III will go out of bounds. // ArrayIndexOutOfBoundsException // The r (rows) will iterate as many times as there are columns. // If there are fewer rows than columns, the index will go out of bounds. for (int r = 0; r < nums[0].length; r++) { for (int c = 0; c < nums.length; c++) { System.out.print (nums[r][c] + " "); } System.out.print ("\n"); } */ } }
Editor Settings
Theme
Key bindings
Full width
Lines