Correct the errors of given program
Attachments:
![](https://hi-static.z-dn.net/files/dc0/6c8ce6aa076c80327ab24b67b80ededc.jpg)
Answers
Answered by
1
Corrected Program:
public class Square
{
public static void main(String args[])
{
int n = 289, r;
r = (int) Math.sqrt(n);
if (r*r==n) {
System.out.println("Perfect Square");
}
else {
System.out.println("Not a Perfect Square");
}
}
}
This is the corrected program, bolded parts are either I've added or corrected...
Answered by
3
Answer:
This is the corrected program for this question.
class Square {
public static void main(String args[]) {
int n=289, r;
r=(int)Math.sqrt(n);
if(r*r==n)
System.out.println("Perfect Square.");
else
System.out.println("Not a Perfect Square.");
}
}
Explanation:
- To find square root, Math.sqrt() function is used. As r is integer, so, we have forcibly converted square root of n to int (as return type of sqrt() function is double)
- Besides correcting the syntax errors, the logical errors are also corrected.
Similar questions