Skip to content

Instantly share code, notes, and snippets.

@viveknarang
Created September 1, 2018 05:29
Show Gist options
  • Save viveknarang/8a21db713206b18b0870d1a1d97ccbed to your computer and use it in GitHub Desktop.
Save viveknarang/8a21db713206b18b0870d1a1d97ccbed to your computer and use it in GitHub Desktop.
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