Computer Applications

class Simplify
{
public static void main(String args[])
{
int a,b,c,d;
a=10,b=5,c=1;
c=2a+2b;
d=(a+b)2;
p=c/d;
System.out.println(c , d , p);
}
}

Input in Java

19 Likes

Answer

Errors in the snippet
  1. Multiple variable assignment statements cannot be separated by a comma. Semicolon should be used instead.
  2. The line c=2a+2b needs an operator between 2 and a, 2 and b.
  3. The line d=(a+b)2 needs an operator between (a+b) and 2.
  4. Variable p is not defined.
  5. println method takes a single argument.
Corrected Program
class Simplify
{
public static void main(String args[])
{
int a,b,c,d;
a=10;b=5;c=1;    //1st correction
c=2*a+2*b;         //2nd correction
d=(a+b) / 2;            //3rd correction
int p=c/d;                  //4th correction
System.out.println(c + " " + d + " " + p);  //5th correction
}
}

Answered By

13 Likes


Related Questions