Advertisement
Ivan18113

Task3

Apr 13th, 2021
734
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.90 KB | None | 0 0
  1. package HomeWork_Programming;
  2.  
  3. import java.util.*;
  4. import java.lang.Math;
  5.  
  6. public class Task3 {
  7.     public static void main(String[] args) {
  8.         Scanner scan = new Scanner(System.in);
  9.  
  10.         //Creating LinkedList
  11.         LinkedList ll = new LinkedList();
  12.  
  13.         int n;
  14.         do {                                      //Input only positive numbers
  15.             n = Integer.parseInt(scan.nextLine());
  16.             if (Math.sqrt(n) == Math.round(Math.sqrt(n))){       //Check if number is square root and add to list
  17.                 ll.add(n);
  18.             }
  19.         }
  20.         while(n > 0);     //Exit is with negative value
  21.  
  22.         Collections.sort(ll,  Collections.reverseOrder());    //Sort the list in descending order
  23.         for (int i = 0; i <ll.size(); i++) {          //Output results
  24.             System.out.print(ll.get(i)+ " ");
  25.         }
  26.  
  27.     }//end of main
  28. }//end of class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement