Computer Applications
Correct the errors in the given program:
class Simplify
{
public static void main(String args[])
{
int a,b,c,d;
a=10,b=5,c=1,d=2;
c=a2+b2;
d=(a+b)2;
p=c/d;
System.out.println(c + " "+ " "+d+ " "+p);
}
}
Java Conditional Stmts
29 Likes
Answer
Explanation
- The line
a=10,b=5,c=1,d=2;
generates a compile time error. We will combine the declaration and initialization of these variables. - The line c=a2+b2; is written in Java like this c = (int)(Math.pow(a, 2) + Math.pow(b, 2));
- The line d=(a+b)2; is written in Java like this d=(int)Math.pow((a+b), 2);
- Variable p is not defined
Corrected Program
class Simplify
{
public static void main(String args[])
{
int a=10,b=5,c=1,d=2; //1st correction
c = (int)(Math.pow(a, 2) + Math.pow(b, 2)); //2nd correction
d = (int)Math.pow((a+b), 2); //3rd correction
int p=c/d; //4th correction
System.out.println(c + " "+ " "+d+ " "+p);
}
}
Answered By
20 Likes
Related Questions
Correct the errors in the given program:
class public { public static void main(String args{}) { int a=45,b=70,c=65.45; sum=a+b; diff=c-b; System.out.println(sum,diff); } }
Correct the errors in the given program:
class Square { public static void main(String args[]) { int n=289,r; r=sqrt(n); if(n==r) System.out.println("Perfect Square"); else System.out.println("Not a Perfect Square"); } }
Correct the errors in the given program:
class Sample { public static void main(String args[]) { int n,p; float k,r; n=25;p=12; if(n=25) { k=pow(p,2) System.out.println("The value of"+p+ " = "+k); } else { r=Math.square root(n); System.out.println("The value of"+n+ " = "+r); } } }
Write a program to input three angles of a triangle and check whether a triangle is possible or not. If possible then check whether it is an acute-angled triangle, right-angled or an obtuse-angled triangle otherwise, display 'Triangle not possible'.
Sample Input: Enter three angles: 40, 50, 90
Sample Output: Right=angled Triangle