How many times will the following do-while loop be executed? int x = 11; do { x
ID: 3869037 • Letter: H
Question
How many times will the following do-while loop be executed?
int x = 11;
do
{
x += 20;
} while (x > 100);
For the following code, what would be the value of str[2]?
String [ ] str = {“abc”, “def”, “ghi”, “jkl”};
What will be displayed after the following code has been executed?
String str1 = “The quick brown fox jumped over the lazy dog.”;
String str2 = str1.substring(20,26);
What will be the result of the following code:
int[ ] numbers = {40, 3, 5, 7, 8, 12, 10};
int value = numbers[0];
for (int i=1; i< numbers.length; i++)
{ if (numbers[i] < value)
value = numbers[i];
}
What will be the result of the following code:
Int[ ] numbers = {40, 3, 5, 7, 8, 12, 10};
int value = 0
; for (int i=1; i< numbers.length; i++)
{ if (numbers[i] < value)
value += numbers[i];
}
What does the following code do:
String str = “abc456”;
char chr = str.charAt(2);
If (Character.isLetter(chr))
System.out.print(Character.toUpperCase(chr));
Explanation / Answer
1- The Do while loop will execute 5 times as
1st iteration it will enter loop without any condition as it is a do while loop before leaving the value of x=11+20=31 condition is truee 31<100 so it will run 2nd time now at the end of loop x=31+20=51 again condition is true so loop will be executed 3rd time now again x=51+20=71 now again condition is true loop will run 4th time now x=71+20=91 now condition is true loop will execute 5th time now x=91+20=111 condition becomes false to loop will terminate. so like this loop will execute 5 times.
2-the value of str[2]=ghi as the values of loop will start at index 0.
3-if str2 is printed jumped will be printed as at index 20 j and it will take till 26-1 i.e 25 so jumped will be printed.
4-3 will be printed as it stores the minimum value in the value vaiable.
5-0 will be printed as no value in array is less than 0 so 0 will be printed.
6-C will be printed as at 2 index there is c if condition is satisfied to it is converted to upercase so C will be printed.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.