Computer Science, asked by Lonewolf66613, 3 months ago

write a program in java to input two unequal positive numbers and check wheather they are perfect square numbers or not.If the users enter a negitive number then the program displays the message 'square root of a negitive cant be dertermined' with scanner class?

Answers

Answered by harshika7257
0

Answer:

Java Program :

public class greatest_of_three

{

public static void main(int a,int b,int c)

{

int d=0;

int e=0;

if (a>b && a>c)

d=a;

if (b>a && b>c)

d=b;

if (c>a && c>b)

d=c;

if (a<b && a<c)

e=a;

if (b<a && b<c)

e=b;

if (c<a && c<b)

e=c;

System.out.println("Among the inputs done i.e. "+a+","+b+","+c);

System.out.println("The greatest number = "+d);

System.out.println("The smallest number = "+e);

}

}

Input :

a=10

b=20

c=30

Output :

Among the inputs done i.e. 10,20,30

The greatest number = 30

The smallest number = 10

Answered by Oreki
3

import java.util.Scanner;  

public class PerfectSquares {

   static boolean isPerfectSquare(double number) {

       double squareRoot = Math.sqrt(number);

       return (squareRoot - Math.floor(squareRoot)) == 0;

   }

   static void printPerfect(int number) {

       if (!(number <= 0))

           System.out.printf("%d is%sa Perfect Square\n", number, isPerfectSquare(number) ? " " : " not ");

       else System.out.println(number + " is negative!");

   }

   public static void main(String[ ] args) {

       Scanner sc = new Scanner(System.in);

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

       printPerfect(sc.nextInt( ));

       printPerfect(sc.nextInt( ));

   }

}


Oreki: Thanks!
Similar questions