What is the output of this program?
public class Test{
public static void main(String args[]X
int x = 2;
int y = 0
for (; y<10; ++y){
if (y % X == 0)
continue
else if (y == 8)
break;
else
System.out.print(y + " ");
سس سه
.
www.
Answers
Following are the output of the given java code:
Output:
1 3 5 7 9
Explanation:
In the given code there is some mistype error so, the correct code this question can be defined as follows:
public class Test//defining a class Test
{
public static void main(String[] args)//defining the main method
{
int x = 2;//defining integer variable x and assign a value "2"
int y = 0;//defining integer variable y and assign a value "0"
for (; y<10; ++y) //defining a for loop to count values from 0 to 9
{
if (y % x == 0)//defining if block that checks the value is divisiable by 2
continue ;//use continue keyword
else if (y == 8)//defining else if block that checks value equal to 8
break;//use break keyword
else//defining else block
System.out.print(y + " "); //print value with single space
}
} }
Explain:
- In the above-given code, inside the main method two integer variable "x and y" is declared that holds some values and a for loop is defined, that uses the conditional statement.
- In the if block, it checks the value if it is even. so, it uses the continue keyword, in the next condition if the value equal to 8, it uses the break keyword.
- At the last, in else block it prints all odd values.
Learn more:
- Output: https://brainly.in/question/18420739