Computer Science, asked by shreyansh9918, 5 months ago

Identify and write the error in the following program and also write the correct code: [2]
double x = 10;
int y=x;
System.out.println(y);

Answers

Answered by riyaamen303
1

Answer:

The error is declaring x of double and assigning it's value to variable y of int datatype.

So,the program can be written as follows:

public class MyClass {

   public static void main(String args[]) {

     int x = 10;

double y=x;

System.out.println(y);

   }

}

                                                        or

public class MyClass {

   public static void main(String args[]) {

     int x = 10;

     int y=x;

System.out.println(y);

   }

}

Hope this helps you.Please add as Brainliest if it is correct.

Similar questions