GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

Consider the following method. public static String changeS…

Consider the following method. public static String changeStr(String str) { String result = “”; for (int i = str.length() – 1; i >= str.length() / 2; i -= 2) { result += str.substring(i, i + 1); } return result; } What value is returned as a result of the method call changeStr(“12345”) ?

Read Details

Consider the following code segment. int j = 1; while (j <...

Consider the following code segment. int j = 1; while (j < 5) { int k = 1; while (k < 5) { System.out.println(k); k++; } j++; } Which of the following best explains the effect, if any, of changing the first line of code to int j = 0; ?

Read Details

A bear is an animal and a zoo contains many animals, includi…

A bear is an animal and a zoo contains many animals, including bears. Three classes Animal, Bear, and Zoo are declared to represent animal, bear, and zoo objects. Which of the following is the most appropriate set of declarations? A public class Animal extends Bear {   … } public class Zoo {   private Animal[] myAnimals;   … } B public class Bear extends Animal {   … } public class Zoo {   private Animal[] myAnimals;   … } C public class Animal extends Zoo {   private Bear myBear;   … } D public class Bear extends Animal, Zoo {   … } E public class Bear extends Animal implements Zoo {   … }

Read Details

Consider the following code segment. int count = 5; while (…

Consider the following code segment. int count = 5; while (count < 100) { count = count * 2; } count = count + 1; What will be the value of count as a result of executing the code segment?

Read Details

Consider the following method. public static int calcMethod…

Consider the following method. public static int calcMethod(int num) { if (num == 0) { return 10; } return num + calcMethod(num / 2); } What value is returned by the method call calcMethod(16) ?

Read Details

Consider the following recursive method. public static void…

Consider the following recursive method. public static void stars(int num) { if (num == 1) { return; }   stars(num – 1);   for (int i = 0; i < num; i++) { System.out.print("*"); } System.out.println(); } What is printed as a result of the method call stars(5) ?   A ***** B ** *** **** ***** C * ** *** **** ***** D ***** **** *** ** E ***** **** *** ** *

Read Details

The bark method below is intended to print the string “woof”…

The bark method below is intended to print the string “woof” a total of num times. public static void bark(int num) { if (num > 0) { System.out.println(“woof”); /* missing code */ } } Which of the following can be used to replace /* missing code */ so that the call bark(5) will cause “woof” to be printed five times?

Read Details

Consider the following method. public static int mystery(in…

Consider the following method. public static int mystery(int n) { if (n

Read Details

Consider the following recursive method. public static Strin…

Consider the following recursive method. public static String recur(int val) {   String dig = “” + (val % 3);     if (val / 3 > 0)     return dig + recur(val / 3);     return dig; }   What is printed as a result of executing the following statement? System.out.println(recur(32));

Read Details

Consider the following recursive method. private int recur(i…

Consider the following recursive method. private int recur(int n) {   if (n

Read Details

Posts pagination

Newer posts 1 … 38,049 38,050 38,051 38,052 38,053 … 68,196 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top