Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

What will the following code do? Assume s is a String, x is an int initialized t

ID: 3779069 • Letter: W

Question

What will the following code do? Assume s is a String, x is an int initialized to 10, page is a Graphics object, and this is part of a paint method for an applet. boolean isVowel = false; String vowels = "aeiou"; for (int j = 0; j < s.length( ); j++) { for (int k = 0; k < 5; k++) if (s.charAt(j) == vowels.charAt(k)) isVowel = true; if (isVowel) page.drawString(""+s.charAt(j), 10, 15*x++); else page.drawString(""+s.charAt(j), 110, 15*x++); isVowel = false; } 1. The String s is printed down the applet in two columns with vowels appearing in the right column and all other characters in the left column 2. The String s is printed across the applet with vowels printed in one row and all other characters printed in a row below the vowels 3. The String s is printed down the applet in two columns, alternating each letter 4. The String s is printed across the applet with vowels printed in one row and all other characters printed in a row above the vowels 5. The String s is printed down the applet in two columns with vowels appearing in the left column and all other characters in the right column

Explanation / Answer

Lets run through your code for a string say Zebra

So, everytime a vowel is encountered, it is printed at x=10, otherwise its printed at x=110

Also, after each iteration, y coordinate is changed from initial value of x in multiples of 15, so say if x=0 at the beginning of this loop, after each iteration y sequence is 0, 15, 30, 45....

So for a string such as zebra, it would look something like (assuming variable x is starting at 0)

So, as we can see the output, 5th option is the correct one.

x=10 x=110 y=0 z y=15 e y=30 b y=45 r y=60 a
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote