What is the result? Given: What is the result? Given: What is the result? A. Out of limits B. Out of limits hEllOjAvA! C. Hello java! D. hEllOjAvA! Show Hint ← Previous question Next question →
Ryan I don’t feel like typing this one out again but the result I got was B. Out of limits hEllOjAvA! Reply
Rajesh public class TestTry { public static void main(String[] args) { StringBuilder message = new StringBuilder(“hello java!”); int pos = 0; try { for(pos = 0 ; pos < 12; pos++) { switch (message.charAt(pos)) { case 'a': case 'e': case 'o': String uc = Character.toString(message.charAt(pos)).toUpperCase(); message.replace(pos, pos + 1, uc); } } } catch (Exception e ) { System.out.println("Out of limits"); } System.out.println(message); } } Correct Answer: Option B: Out of limits hEllO jAvA! Reply
I don’t feel like typing this one out again but the result I got was B.
Out of limits
hEllOjAvA!
I think:
A. Out of limits (only)
message is out of try-catch
But what is the code for the question?
public class TestTry {
public static void main(String[] args) {
StringBuilder message = new StringBuilder(“hello java!”);
int pos = 0;
try {
for(pos = 0 ; pos < 12; pos++) {
switch (message.charAt(pos)) {
case 'a':
case 'e':
case 'o':
String uc = Character.toString(message.charAt(pos)).toUpperCase();
message.replace(pos, pos + 1, uc);
}
}
} catch (Exception e ) {
System.out.println("Out of limits");
}
System.out.println(message);
}
}
Correct Answer:
Option B:
Out of limits
hEllO jAvA!