Computer Science, asked by sachinraj2323, 1 year ago

write a program to input two unequal positive number and check whether they are perfect square or not. if the user in the negative numbers in the program display message 'square root of negative number cannot be determined'.

Answers

Answered by AniketSoftDev
19
i won't write the whole programme just the logic



Scanner sc = new Scanner(System.in);
int a,b;
a= sc.nextInt();
b = sc.nextInt();

if(a<0 // b<0)
System.out.println(message here);
else{
double aa,bb;
aa =math.sqrt(a);
bb = math.sqrt(b);
System.out.println(" a is "+ aa);
System.out.println(" b is "+ bb);
}
Answered by Aneesh777
28

Answer:

HERE'S A SIMPLE ANSWER

HOPE IT HELPS

PLEASE MARK IT AS BRAINLIEST ANSWER

Explanation:

import java.util.*;

class P6

{

   public static void main()

   {

       Scanner sc=new Scanner(System.in);

       System.out.println("Enter two numbers");

       int a=sc.nextInt();

       int b=sc.nextInt();

       if(a<0||b<0)

       {

           System.out.println("Square Root of Negative Number cannot be determined");

       }

       else if(a>0)

       {

           double aa,bb;

           aa =Math.sqrt(a);

           bb =Math.sqrt(b);

           if((aa*aa==a)&&(bb*bb==b))

           {

               System.out.println("These are perfect Squares");

           }

           else

           {

               System.out.println("These are not perfect Squares");

           }

       }

   }

}

Similar questions