Computer Applications
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);
}
}
}
Java Conditional Stmts
46 Likes
Answer
Explanation
- The line
if(n=25)
should beif(n==25)
- The line
k=pow(p,2)
should bek=(float)Math.pow(p,2);
- The line
r=Math.square root(n);
should ber=(float)Math.sqrt(n);
Corrected Program
class Sample
{
public static void main(String args[])
{
int n,p;
float k,r;
n=25;p=12;
if(n==25) //1st correction
{
k=(float)Math.pow(p,2); //2nd correction
System.out.println("The value of"+p+ " = "+k);
}
else
{
r=(float)Math.sqrt(n); //3rd correction
System.out.println("The value of"+n+ " = "+r);
}
}
}
Answered By
30 Likes
Related Questions
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 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); } }
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 TriangleWrite a program to input the cost price and the selling price of an article. If the selling price is more than the cost price then calculate and display actual profit and profit per cent otherwise, calculate and display actual loss and loss per cent. If the cost price and the selling price are equal, the program displays the message 'Neither profit nor loss'.