Advertisement
EmiliaKitkarska

Zadacha3

Apr 19th, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.76 KB | None | 0 0
  1. 3. Числа квадрати
  2.  
  3. import java.util.*;
  4.  
  5. public class Zadachki {
  6.  
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.         String [] input = scan.nextLine().split(" ");
  10.         int arr[] = new int[input.length];
  11.         for (int i = 0; i < input.length; i++) {
  12.             arr[i] = Integer.parseInt(input[i]);
  13.         }
  14.         HashSet set = new HashSet<Integer>();
  15.  
  16.         for(int k:arr){
  17.             double value = Math.sqrt(k);
  18.             if (value == (int) value) {
  19.                 set.add(k);
  20.             }
  21.         }
  22.         List<Integer> result = new ArrayList<>(set);
  23.         Collections.sort(result);
  24.         Collections.reverse(result);
  25.         System.out.println(result);
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement