Created
September 1, 2018 05:29
-
-
Save viveknarang/8a21db713206b18b0870d1a1d97ccbed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package edu.uga; | |
import java.util.Collections; | |
import java.util.LinkedList; | |
import java.util.List; | |
import java.util.Scanner; | |
public class Test { | |
public static void main(String[] args) { | |
Scanner in = new Scanner(System.in); | |
List<Integer> aList = new LinkedList<Integer>(); | |
int count = 1; | |
int x = in.nextInt(); | |
while (x > 0) { | |
if (aList.size() == 0) { | |
aList.add(x); | |
} else { | |
int first_square = aList.get(0) * aList.get(0); | |
if (x >= first_square) { | |
aList.clear(); | |
count++; | |
} else { | |
aList.add(x); | |
} | |
} | |
Collections.sort(aList); | |
System.out.println(aList + " :: " + count); | |
x = in.nextInt(); | |
} | |
in.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment