Vasilena

ProgrammingExercise250321

Mar 25th, 2021
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Scanner;
  3. import java.util.Collections;
  4.  
  5. public class Programming_2_250321 {
  6. public static void main(String[] args) {
  7. ArrayList<Integer> list = new ArrayList<>();
  8. Scanner sc = new Scanner(System.in);
  9. System.out.println("Please, enter the length of the list: ");
  10. int l = sc.nextInt();
  11. System.out.println("Please, enter the elements of the list");
  12. for (int i = 0; i < l; i++) {
  13. int num = sc.nextInt();
  14. list.add(num);
  15. }
  16. System.out.println("Your list is: " + list);
  17.  
  18. ArrayList<Integer> result = new ArrayList<>();
  19.  
  20. for (int i = 0; i < list.size(); i++) {
  21. double sqrt = Math.sqrt(list.get(i));
  22. if(sqrt - Math.floor(sqrt) == 0){
  23. result.add(list.get(i));
  24. }
  25. }
  26.  
  27. Collections.sort(result, Collections.reverseOrder());
  28. System.out.println(result);
  29.  
  30. }
  31. }
  32.  
Advertisement
Add Comment
Please, Sign In to add comment