Largest number that is not a perfect square | Java program to find the largest non perfect square number among n numbers ; takes the sqrt of the number ; checks if it is a perfect square number ; function to find the largest non perfect square number ; stores the maximum of all non perfect square numbers ; traverse for all elements in the array ; store the maximum if not a perfect square ; driver code to check the above functions ; function call
import java . io . * ; class GfG { static Boolean check ( int n ) { int d = ( int ) Math . sqrt ( n ) ; if ( d * d == n ) return true ; return false ; } static int largestNonPerfectSquareNumber ( int a [ ] , int n ) { int maxi = - 1 ; for ( int i = 0 ; i < n ; i ++ ) { if ( ! check ( a [ i ] ) ) maxi = Math . max ( a [ i ] , maxi ) ; } return maxi ; } public static void main ( String [ ] args ) { int a [ ] = { 16 , 20 , 25 , 2 , 3 , 10 } ; int n = a . length ; System . out . println ( largestNonPerfectSquareNumber ( a , n ) ) ; } }