GradePack

    • Home
    • Blog
Skip to content
bg
bg
bg
bg

GradePack

Consider the following code segment. int num1 = 0; int num2…

Consider the following code segment. int num1 = 0; int num2 = 3; while ((num2 != 0) && ((num1 / num2) >= 0)) {   num1 = num1 + 2;   num2 = num2 – 1; } What are the values of numl and num2 after the while loop completes its execution?

Read Details

Consider the following method. public int mystery(int num) {…

Consider the following method. public int mystery(int num) { int x = num; while (x > 0) { if (x / 10 % 2 == 0) return x; x = x / 10; } return x; } What value is returned as a result of the call mystery(1034) ?

Read Details

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

Consider the following code segment. int k = 1; while (k < 20) {   if ((k % 3) == 1)     System.out.print(k + " ");     k++; }   What is printed as a result of executing this code segment?

Read Details

Consider the following two code segments. Code segment II is…

Consider the following two code segments. Code segment II is a revision of code segment I in which the loop header has been changed. I. for (int k = 1; k = 1; k–) { System.out.print(k); } Which of the following best explains how the output changes from code segment I to code segment II?

Read Details

Consider the following method. public String wordPlay(Strin…

Consider the following method. public String wordPlay(String word) { String str = “”; for (int k = 0; k < word.length(); k++) { if (k % 3 == 0) { str = word.substring(k, k + 1) + str; } } return str; } The following code segment appears in another method in the same class as wordPlay. System.out.println(wordPlay("Computer Science")); What is printed as a result of executing the code segment?

Read Details

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

Posts pagination

Newer posts 1 … 44,130 44,131 44,132 44,133 44,134 … 74,277 Older posts

GradePack

  • Privacy Policy
  • Terms of Service
Top