Computer Applications
The following code has some error(s). Identify the errors and write the corrected code.
Int x = 4, y = 8;
{
y = y + (x++)
} while (x <= 10)
System.out.println(y);
Java Iterative Stmts
4 Likes
Answer
The corrected code is as follows:
int x = 4, y = 8;
do
{
y = y + (x++);
} while (x <= 10);
System.out.println(y);
Statement | Error |
---|---|
Int x = 4, y = 8; | int is a keyword and should be written in lowercase |
The user needs to use do while loop | The do-while loop structure is used incorrectly, as the do keyword is missing. |
y = y + (x++) | Semicolon should be written at the end of the statement |
while (x <= 10) | A semicolon should be written after the while(x <= 10) |
Answered By
3 Likes
Related Questions
What will be the output of the following code?
int num = 10; if (num < 20) System.out.print(num++); else System.out.print(--num);
Find the output of the given code.
int a, b = 100; for (a = 10; a <= 12; a++) { b += a; } System.out.print("a:" + a + " " + "b:" + b);
State the method that determines, if the specified character is an uppercase character.
Write the return data type of the following functions.
(a) startsWith( )
(b) log( )