Question: Question 2 1 pts Consider the following method, which is intended to print the first letter of every String in the array words. public static


![public static void printInitials(String[] words) for (Strings : words) { System.out.println(/* missing](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f3b1e58c2d8_82166f3b1e52cd72.jpg)


Question 2 1 pts Consider the following method, which is intended to print the first letter of every String in the array words. public static void printInitials(String[] words) for (Strings : words) { System.out.println(/* missing code */); } } Which of the following should replace /* missing code * so that the method works as intended? words.s.substring(0, 1) words.substring(0, 1) O s.substring(0, 1) O words [5].substring(0, 1) Question 3 1 pts For which of the following tasks would a for-each loop be appropriate? Select all that apply. Printing every element in an array Printing every even number in an array of ints Determining whether an array of Strings is arranged in alphabetical order Printing all the elements at even indices of an array Reversing the order of the elements in an array Determining how many elements in an array of doubles are positive Question 4 1 pts What is printed when the following code segment is run? int[] arr = {3, 5, 8, 10); for (int n : arr) { n = 2; } System.out.println(arr[2]); O 16 O 5 O 09 O 6 Question 5 1 pts What is printed when the following code segment is run? String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"); for (Strings : days) { 5 s.substring(0, 3); } System.out.println(days[0]); & Mond O Monday Nothing is printed. An IndexOutOfBoundsException is thrown. O Mon Question 6 1 pts What is printed when the following code segment is run? Regular Polygon polygons = {new Regular Polygon (3), new Regular Polygon (4), newRegularPolygon (5)}; for (Regular Polygon P: polygons) { if (p.getSides) % 2 == 1) p.addSides(); } 3 for (Regular Polygon P: polygons) 1 System.out.println(); } square with side length 1.0 regular pentagon with side length 1.0 regular hexagon with side length 1.0 square with side length 1.0 square with side length 1.0 regular pentagon with side length 1.0 square with side length 1.0 square with side length 1.0 regular hexagon with side length 1.0 equilateral triangle with side length 1.9 square with side length 1.0 regular pentagon with side length 1.0 Question 7 1 pts What is printed when the following code segment is run? Rectangle[] rectangles = {new Rectangle(4, 1), new Rectangle(2,5), newRectangle(7, 6)}} for (Rectangler: rectangles) { if (r.getPerimeter() > 12) { r.setLength(3); } else { r = new Rectangle(1, 2); } } for (Rectangler: rectangles) { System.out.print(r.getlength() + " "); 3 O 113 0 433 0423 O 427 O 133
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
