Survey
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Name __________________ Counting Iterations How many times does action() execute in the following segments of code? 1) for (int m = 0; m < 29; m++) action(); 29 2) for (int k = 1; k <= 12; k++) action(); action(); 6) for (int t = 0; t < 3; t++) for (int j = t; j <= 9; j++) action(); j=0..9, j=1..9, j=2..9, 10+9+8=27 7) 12+1=13 3) int f; for (f = 1; f <= 21; f++) action(); 21 for (f = 0; f < 5; f++) action(); 5 39 8) 21+5=26 4) for (int n = 0; n <= 8; n++) action(); 9 for (int h = 1; h < 9; h++) action(); 8 for (int c = 0; c < 4; c++) { action(); 4 for (int w = 1; w < 5; w++) action(); 4 * 4 = 16 } for (int y = action(); for (int u = action(); for (int g = action(); 1; y < 15; y+=2) 1,3,5…13 = 7 1; u < 7; u+=3) 1,4 = 2 0; g < 40; g+=5) 0,5,10…35 = 8 7+2+8=17 9) 9+8=17 5) for (int b = 1; b <= 6; b++) { action(); for (int z = b; z < 9; z++) action(); } for (int d = action(); for (int s = for (int k action(); 0; d <= 14; d+=2) 0,2,4,…12,14 = 8 1; s < 16; s+=3) = s; k < 8; k++) 1..7(7), 4..7(4), 7..7(1) 8+7+4+1=20 10) for (int r = 0; r <= 9; r++) for (int z = 0; z < 3; z++) for (int k=0; k < 4; k++) action(); 10*3*4=120 4+16=20 11) int[] values new int[20]; for (int r = 0; r < values.length; r++) if ( r % 3 = = 0 || r % 10 = = r) values[r] = r; else values[r] = -r; What is the value of: a) values[3] = 3 b) values[7] = 7 D:\231209323.doc c) d) values[10] = -10 values[13] = -13 Consider the following class public class Widgets { public int swim(int k) { … } public int swim(int k, boolean f) { … } public int run(int k, int m) { … } public int run(double x) { … } public int run(int k, double x) { … } } Which of the following method(s) can be added to Widgets and NOT cause a compile error? public void swim(int w) { … } public int swim(int[] k) { … } public int swim(int k, int g) { … } public int swim(boolean f, int k) { … } public void run (double x, int w) { … } public int run (int[] k) { … } public int run (int m, int k) { … } public int run (int k, int r, int j) { … } Consider the following code segment, find the indicated values: int[] nums = {21, 40, 54, 13, 1, 25, 21, 25, 17, 11, 33, 40, 25} int d = 0; for (int r = 0; r < nums.length; r++) if ( nums[r] < nums[0] ) d++; r = 3, 4, 8, 9 int w = 0; for (int r = 0; r < nums.length; r++) if ( nums[r] < 2 * r ) w++; r = 4, 9 int y = 0; for (int r = 0; r < nums.length; r++) if ( nums[r] / 10 > nums[r] % 10 ) y++; r = 0, 1, 2, 6, 11 int h = 0; for (int r = 0; r < nums.length / 2; r++) if ( nums[r] = = num[num.length – r - 1] ) h++; d = 4 D:\231209323.doc w = 2 y = 5 r = 1, 5 h = 2