JAVA / I KNOW THERE IS MORE THAN ONE QUESTION BUT THEY ARE SO EASY FO YOU I NEED YOUR HELP PLEASE HELP ME. I WILL GIVE UPVOTE AND GOOD COMMENT THANK YOU SO MUCH !!!
QUESTION 1
What is the output after the code executes? Assume there are no syntax errors and the code will compile.
int x = 10;
do
{
System.out.println ( x );
x -= 3;
}
while (x > 0);
A. |
|
|
B. |
|
|
C. |
10, 7, 4, 1 |
|
D. |
1, 4, 7, 10 |
QUESTION 2
What is the value of x after the loop is done executing? Assume there are no syntax errors and the code will compile.
int x = 10;
do
{
System.out.println ( x );
x -= 3;
}
while (x > 0);
A. |
10 |
|
B. |
1 |
|
C. |
0 |
|
D. |
-1 |
|
E. |
-2 |
QUESTION 3
What is the output of the program segment? Assume there are no syntax errors and the code will compile.
int i = 1;
int n = 0;
do
{
System.out.print( i );
i++;
}
while (i <= n);
A. |
0 |
|
B. |
1 |
|
C. |
-1 |
|
D. |
2 |
QUESTION 4
What are the values of i and n after execution? Assume there are no syntax errors and the code will compile.
int i = 1;
int n = 0;
do
{
System.out.print( i );
i++;
}
while (i <= n);
A. |
i = 1 and n = 0 when done. |
|
B. |
i = 0 and n = 1 when done. |
|
C. |
i = 2 and n = 0 when done. |
|
D. |
i = -1 and n = 2 when done. |
QUESTION 5
What is the output of the following program segment?
Assume there are no syntax errors and the code will compile.
int x = 4;
do
{
System.out.println ( x );
x += 2;
}
while (x > 0);
A. |
|
|
B. |
0, 0, 0, 0 |
|
C. |
Will not loop at all. |
|
D. |
Infinite loop. |
QUESTION 6
What is the value of x when the loop is done? Assume there are no syntax errors and the code will compile.
int x = 4;
do
{
System.out.println ( x );
x += 2;
}
while (x > 0);
A. |
x will stay at 4. |
|
B. |
The loop is infinite so x will keep getting larger. |
|
C. |
x will be less than zero. |
|
D. |
x will be zero. |
QUESTION 7
What is the output of the following program segment? Assume there are no syntax errors and the code will compile.
int i;
int n = 0;
for (i = 1; i <= n; i++)
System.out.print (i);
A. |
There is no output. |
|
B. |
Output: 1 |
|
C. |
Output: 0 |
|
D. |
Output: -1 |
Question -1 -->
Answer is A
here, x = 10 and while loop continues till the value of x is greater than 0
so, first it will print 10 on the screen, and then the line is changed,
and then, x- = 3 ==> x = x - 3 ==> x = 10 - 3 = > x =7
so, loop will continue,
now, it will print 7 on the screen and then the line will be changed,
and then x-3 ==> x = 4.
so, loop will continue,
now, it will print 4 on the screen and then the line will be changed,
and then x-3 ==> x = 1.
so, loop will continue,
now, it will print 1 on the screen and then the line will be changed,
and then x-3 ==> x = -2
now loop will be terminated.
And so output will be -->
10
7
4
1
So, answer is A..
Get Answers For Free
Most questions answered within 1 hours.