kbd.next(); String word = kbd.next(); int wordLen = word.length(); for (int j = 0; j < wordLen; j += 2) { System.out.print(word.charAt(j)); }
Assume that kbd is our usual Scanner beastie getting keyboard input.
If a user enters good morning and hits Enter, what will the above code print out?
int i = 0; boolean done = false; int n = -1; while (i <= nums.size() && !done) { n = nums.get(i); if (n < 3) { done = true; } i += 1; }
Assume the ArrayList<Integer> nums contains these integers:
What values do i and n have when the loop completes?
Is there a potential bug in this code? Where?
By Jordan Pratt