Computer Science, asked by Anonymous, 5 months ago

for(int x=1, y=2; x<=y; x++)

{

y=x*y;

System.out.println(y);

}

System.out.println(x);​

Answers

Answered by rajguttedar3
0

Answer:

x=1, y=2

Explanation:

2=1*2

2=2................

Answered by madhavivinod10
0

Answer:

Error Code

Explanation:

okay so... here is the problem in this code:

for(int x=1, y=2; x<=y; x++)

{

          y=x*y;

          System.out.println(y);

}

System.out.println(x);

here int x is declared specifically for the given For loop , you cannot use it outside of for loop.

so it will give you error like :

prog.java:17: error: cannot find symbol

System.out.println(x);

for loop can only declare 1 value at a time so declaring x, y at same time in a for loop is Bad

Solution:

public static void main(String[] args)

{

   int x;

   int y=2;

   for(x=1 ; x<=y; x++)

   {

              y=x*y;

              System.out.println(y);

   }

   System.out.println(x);

}

Output:

2

4

12

48

240

1440

10080

80640

725760

7257600

79833600

958003200

-430860288          //values of y total 14

14        //value of x

Similar questions