Computer Science, asked by BhushanKisalay, 6 months ago

Correct the errors of given program​

Attachments:

Answers

Answered by atrs7391
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 anindyaadhikari13
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