Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.ArrayList;
- import java.util.Scanner;
- import java.util.Collections;
- public class Programming_2_250321 {
- public static void main(String[] args) {
- ArrayList<Integer> list = new ArrayList<>();
- Scanner sc = new Scanner(System.in);
- System.out.println("Please, enter the length of the list: ");
- int l = sc.nextInt();
- System.out.println("Please, enter the elements of the list");
- for (int i = 0; i < l; i++) {
- int num = sc.nextInt();
- list.add(num);
- }
- System.out.println("Your list is: " + list);
- ArrayList<Integer> result = new ArrayList<>();
- for (int i = 0; i < list.size(); i++) {
- double sqrt = Math.sqrt(list.get(i));
- if(sqrt - Math.floor(sqrt) == 0){
- result.add(list.get(i));
- }
- }
- Collections.sort(result, Collections.reverseOrder());
- System.out.println(result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment