题解 | #兔子的序列#

兔子的序列

https://www.nowcoder.com/practice/55fc2ebad3fd444bbb1754ba1b259762

import java.util.Scanner;

// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] nums = new int[n];
        int res = 0;
        int numTemp;
        for(int i = 0;i < n; i++){
              numTemp = in.nextInt();
            if(!isPerfectSquares(numTemp)){
                if(numTemp > res){
                    res = numTemp;
                }
            }
        }
        System.out.println(res);
        

    }
    public static boolean isPerfectSquares(int num){
        int n = (int) Math.sqrt(num);
        if( n * n  == num){
            return true;
        }else{
            return false;
        }
    }

}

全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务