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

 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? O s.substring(0, 1) words.

s.substring(0, 1) O words.substring(0, 1) words[s].substring(0, 1) Question 3 For which of

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? O s.substring(0, 1) words. s.substring(0, 1) O words.substring(0, 1) words[s].substring(0, 1) Question 3 For which of the following tasks would a for-each loop be appropriate? Select all that apply. Printing every even number in an array of ints O Printing every element in an array Determining how many elements in an array of doubles are positive Printing all the elements at even indices of an array Determining whether an array of Strings is arranged in alphabetical order Reversing the order of the elements in an array Question 4 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 8 6 05 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) { s = s.substring(0, 3); 1 System.out.println(days[0]); Nothing is printed. An IndexOutOfBoundsException is thrown. Mond O Monday 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), newRegular Polygon (5)}; for (Regular Polygon P: polygons) { if (p.getSides() % 2 == 1) p.addSides(); } } for (Regular Polygon p : polygons) { System.out.println(); square with side length 1.0 square 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.2 regular pentagon with side length 1.0 regular hexagon with side length 1.0 equilateral triangle with side length 1.0 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() + 0 133 0423 433 0427 0 113

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!