Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package HomeWork_Programming;
- import java.util.*;
- import java.lang.Math;
- public class Task3 {
- public static void main(String[] args) {
- Scanner scan = new Scanner(System.in);
- //Creating LinkedList
- LinkedList ll = new LinkedList();
- int n;
- do { //Input only positive numbers
- n = Integer.parseInt(scan.nextLine());
- if (Math.sqrt(n) == Math.round(Math.sqrt(n))){ //Check if number is square root and add to list
- ll.add(n);
- }
- }
- while(n > 0); //Exit is with negative value
- Collections.sort(ll, Collections.reverseOrder()); //Sort the list in descending order
- for (int i = 0; i <ll.size(); i++) { //Output results
- System.out.print(ll.get(i)+ " ");
- }
- }//end of main
- }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement