Given the following code snippet: String[] animals = {“cat”,…
Given the following code snippet: String[] animals = {“cat”, “elephant”, “dog”, “giraffe”, “zebra”};String selectedAnimal = animals[0];int maxLength = animals[0].length(); for (String anAnimal : animals) { if (anAnimal.length() > maxLength) { maxLength = anAnimal.length(); selectedAnimal = anAnimal; }} System.out.println(selectedAnimal + ” ” + maxLength); What is the output of this code?
Read DetailsWe have defined an overloaded method called printName with 3…
We have defined an overloaded method called printName with 3 different versions. Decide which version will be called by the following statement so you can predict what the output will be: printName(“Ana”, 210); public static void printName(String name, int id) { System.out.print(name + ” ID: ” + id);} public static void printName(int id) { System.out.print(“Name” + ” ID: ” + id);} public static void printName(String name, int id, int age) { System.out.print(name + ” ID: ” + id + ” age: ” + age);}
Read DetailsWhat will the following code output if the variable score is…
What will the following code output if the variable score is set to 75? if (marks >= 90) { System.out.println(“A”);} else if (marks >= 80) { if (marks > 85 && marks < 90) { System.out.println("B+"); } else { System.out.println("B"); }} else if (marks >= 70) { if (marks >= 75) { System.out.println(“C+”); } else { System.out.println(“C”); }} else { System.out.println(“D or lower”);}
Read Details