Consider the following code segments.     I.   int k = 1;  …

Consider the following code segments.     I.   int k = 1;     while (k < 20)     {       if (k % 3 == 1)         System.out.print( k + " ");         k = k + 3;     }      II.   for (int k = 1; k < 20; k++)     {       if (k % 3 == 1)         System.out.print( k + " ");     }      III.  for (int k = 1; k < 20; k = k + 3)     {       System.out.print( k + " ");     }   Which of the code segments above will produce the following output?     1 4 7 10 13 16 19

The following method is intended to print the number of digi…

The following method is intended to print the number of digits in the parameter num. public int numDigits(int num) { int count = 0; while (/* missing condition */) { count++; num = num / 10; } return count; } Which of the following can be used to replace /* missing condition */ so that the method will work as intended?

Consider the following method. public static String abMetho…

Consider the following method. public static String abMethod(String a, String b) { int x = a.indexOf(b);   while (x >= 0) { a = a.substring(0, x) + a.substring(x + b.length()); x = a.indexOf(b); }   return a; } What, if anything, is returned by the method call abMethod(“sing the song”, “ng”) ?

Consider the following method. /** Precondition: Strings on…

Consider the following method. /** Precondition: Strings one and two have the same length. */ public static String combine(String one, String two) { String res = “”; for (int k = 0; k < one.length(); k++) { if (one.substring(k, k + 1).equals(two.substring(k, k + 1))) { res += one.substring(k, k + 1); } else { res += "0"; } } return res; } What is returned as a result of the call combine("10110", "01100") ?