OCP Oracle Certified Professional Java SE 17 Developer Study Guide. Jeanne Boyarsky

OCP Oracle Certified Professional Java SE 17 Developer Study Guide - Jeanne Boyarsky


Скачать книгу
= 0; 3: do { 4: int snake = 1; 5: System.out.print(snake++ + " "); 6: iguana--; 7: } while (snake <= 5); 8: System.out.println(iguana); 1 2 3 4 -4.01 2 3 4 -5.01 2 3 4 5 -4.00 1 2 3 4 5 -5.0The code does not compile.The code compiles but produces an infinite loop at runtime.None of the above

      20 Which statements, when inserted into the following blanks, allow the code to compile and run without entering an infinite loop? (Choose all that apply.)4: int height = 1; 5: L1: while(height++ <10) { 6: long humidity = 12; 7: L2: do { 8: if(humidity-- % 12 == 0) ________________; 9: int temperature = 30; 10: L3: for( ; ; ) { 11: temperature++; 12: if(temperature>50) ________________; 13: } 14: } while (humidity > 4); 15: }break L2 on line 8; continue L2 on line 12continue on line 8; continue on line 12break L3 on line 8; break L1 on line 12continue L2 on line 8; continue L3 on line 12continue L2 on line 8; continue L2 on line 12None of the above, as the code contains a compiler error

      21 A minimum of how many lines need to be corrected before the following method will compile?21: void findZookeeper(Long id) { 22: System.out.print(switch(id) { 23: case 10 -> {"Jane"} 24: case 20 -> {yield "Lisa";}; 25: case 30 -> "Kelly"; 26: case 30 -> "Sarah"; 27: default -> "Unassigned"; 28: }); 29: }ZeroOneTwoThreeFourFive

      22 What is the output of the following code snippet? (Choose all that apply.)2: var tailFeathers = 3; 3: final var one = 1; 4: switch (tailFeathers) { 5: case one: System.out.print(3 + " "); 6: default: case 3: System.out.print(5 + " "); 7: } 8: while (tailFeathers> 1) { 9: System.out.print(--tailFeathers + " "); }35 15 23 5 15 2 1The code will not compile because of lines 3–5.The code will not compile because of line 6.

      23 What is the output of the following code snippet?15: int penguin = 50, turtle = 75; 16: boolean older = penguin>= turtle; 17: if (older = true) System.out.println("Success"); 18: else System.out.println("Failure"); 19: else if(penguin != 50) System.out.println("Other");SuccessFailureOtherThe code will not compile because of line 17.The code compiles but throws an exception at runtime.None of the above

      24 Which of the following are possible data types for friends that would allow the code to compile? (Choose all that apply.) for(var friend in friends) { System.out.println(friend); }SetMapStringint[]CollectionStringBuilderNone of the above

      25 What is the output of the following code snippet?6: String instrument = "violin"; 7: final String CELLO = "cello"; 8: String viola = "viola"; 9: int p = -1; 10: switch(instrument) { 11: case "bass" : break; 12: case CELLO : p++; 13: default: p++; 14: case "VIOLIN": p++; 15: case "viola" : ++p; break; 16: } 17: System.out.print(p); -10123The code does not compile.

      26 What is the output of the following code snippet? (Choose all that apply.)9: int w = 0, r = 1; 10: String name = ""; 11: while(w < 2) { 12: name += "A"; 13: do { 14: name += "B"; 15: if(name.length()>0) name += "C"; 16: else break; 17: } while (r <=1); 18: r++; w++; } 19: System.out.println(name);ABCABCABCABCABCABCLine 15 contains a compilation error.Line 18 contains a compilation error.The code compiles but never terminates at runtime.The code compiles but throws a NullPointerException at runtime.

      27 What is printed by the following code snippet?23: byte amphibian = 1; 24: String name = "Frog"; 25: String color = switch(amphibian) { 26: case 1 -> { yield "Red"; } 27: case 2 -> { if(name.equals("Frog")) yield "Green"; } 28: case 3 -> { yield "Purple"; } 29: default -> throw new RuntimeException(); 30: }; 31: System.out.print(color);RedGreenPurpleRedPurpleAn exception is thrown at runtime.The code does not compile.

      28 What is the output of calling getFish("goldie")?40: void getFish(Object fish) { 41: if (!(fish instanceof String guppy)) 42: System.out.print("Eat!"); 43: else if (!(fish instanceof String guppy)) { 44: throw new RuntimeException(); 45: } 46: System.out.print("Swim!"); 47: }Eat!Swim!Eat! followed by an exception.Eat!Swim!An exception is printed.None of the above

      29 What is the result of the following code?1: public class PrintIntegers { 2: public static void main(String[] args) { 3: int y = -2; 4: do System.out.print(++y + " "); 5: while(y <= 5); 6: } }-2 -1 0 1 2 3 4 5-2 -1 0 1 2 3 4-1 0 1 2 3 4 5 6-1 0 1 2 3 4 5The code will not compile because of line 5.The code contains an infinite loop and does not terminate.

      Конец ознакомительного фрагмента.

      Текст предоставлен ООО «ЛитРес».

      Прочитайте эту книгу целиком, купив полную легальную версию на ЛитРес.

      Безопасно оплатить книгу можно банковской картой Visa, MasterCard, Maestro, со счета мобильного телефона, с платежного терминала, в салоне МТС или Связной, через PayPal, WebMoney, Яндекс.Деньги, QIWI Кошелек, бонусными картами или другим удобным Вам способом.

/9j/4AAQSkZJRgABAQEBLAEsAAD/7SVyUGhvdG9zaG9wIDMuMAA4QklNBAQAAAAAAAccAgAAAgAA ADhCSU0EJQAAAAAAEOjxXPMvwRihontnrcVk1bo4QklNBDoAAAAAAPcAAAAQAAAAAQAAAAAAC3By aW50T3V0cHV0AAAABQAAAABQc3RTYm9vbAEAAAAASW50ZWVudW0AAAAASW50ZQAAAABDbHJtAAAA D3ByaW50U2l4dGVlbkJpdGJvb2wAAAAAC3ByaW50ZXJOYW1lVEVYVAAAAAoAQQBkAG8AYgBlACAA UABEAEYAAAAAAA9wcmludFByb29mU2V0dXBPYmpjAAAADABQAHIAbwBvAGYAIABTAGUAdAB1AHAA AAAAAApwcm9vZlNldHVwAAAAAQAAAABCbHRuZW51bQAAAAxidWlsdGluUHJvb2YAAAAJcHJvb2ZD TVlLADhCSU0EOwAAAAACLQAAABAAAAABAAAAAAAScHJpbnRPdXRwdXRPcHRpb25zAAAAFwAAAABD cHRuYm9vbAAAAAAAQ2xicmJvb2wAAAAAAFJnc01ib29sAAAAAABDcm5DYm9vbAAAAAAAQ250Q2Jv b2wAAAAAAExibHNib29sAAAAAABOZ3R2Ym9vbAAAAAAARW1sRGJvb2wAAAAAAEludHJib29sAAAA AABCY2tnT2JqYwAAAAEAAAAAAABSR0JDAAAAAwAAAABSZCAgZG91YkBv4AAAAAAAAAAAAEdybiBk b3ViQG/gAAAAAAAAAAAAQmwgIGRvdWJAb+AAAAAAAAAAAABCcmRUVW50RiNSbHQAAAAAAAAAAAAA AABCbGQgVW50RiNSbHQAAAAAAAAAAAAAAABSc2x0VW50RiNQeGxAcsAAAAAAAAAAAAp2ZWN0b3JE YXRhYm9vbAEAAAAAUGdQc2VudW0AAAAAUGdQcwAAAABQZ1BDAAAAAExlZnRVbnRGI1JsdAAAAAAA AAAAAAAAAFRvcCBVbnRGI1JsdAAAAAAAAAAAAAAAAFNjbCBVbnRGI1ByY0BZAAAAAAAAAAAAEGNy b3BXaGVuUHJpbnRpbmdib29sAAAAAA5jcm9wUmVjdEJvdHRvbWxvbmcAAAAAAAAADGNyb3BSZWN0 TGVmdGxvbmcAAAAAAAAADWNyb3BSZWN0UmlnaHRsb25nAAAAAAAAAAtjcm9wUmVjdFRvcGxvbmcA AAAAADhCSU0D7QAAAAAAEAEsAAAAAQACASwAAAABAAI4QklNBCYAAAAAAA4AAAAAAAAAAAAAP4AA ADhCSU0EDQAAAAAABAAAAFo4QklNBBkAAAAAAAQAAAAeOEJJTQPzAAAAAAAJAAAAAAAAAAABADhC SU0nEAAAAAAACgABAAAAAAAAAAI4QklNA/UAAAAAAEgAL2ZmAAEAbGZmAAYAAAAAAAEAL2ZmAAEA oZmaAAYAAAAAAAEAMgAAAAEAWgAAAAYAAAAAAAEANQAAAAEALQAAAAYAAAAAAAE4QklNA/gAAAAA AHAAAP////////////////////////////8D6AAAAAD/////////////////////////////A+gA AAAA/////////////////////////////wPoAAAAAP////////////////////////////8D6AAA OEJJTQQIAAAAAAAQAAAAAQAAAkAAAAJAAAAAADhCSU0EHgAAAAAABAAAAAA4QklNBBoAAAAAA08A AAAGAAAAAAAAAAAAAArXAAAIpQAAAA0AOQA3ADgAMQAxADEAOQA4ADYANAA1ADgANQAAAAEAAAAA AAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAAAAAIpQAACtcAAAAAAAAAAAAAAAAAAAAAAQAAAAAAAAAA AAAAAAAAAAAAAAAQAAAAAQA

Скачать книгу