Skip to content

Instantly share code, notes, and snippets.

@derekmc
Created September 7, 2025 15:28
Show Gist options
  • Select an option

  • Save derekmc/e172730b8ecba468ac109f53d81022b3 to your computer and use it in GitHub Desktop.

Select an option

Save derekmc/e172730b8ecba468ac109f53d81022b3 to your computer and use it in GitHub Desktop.
//import java.io.File;
//import java.io.FileNotFoundException;
//import java.util.Scanner;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.ArrayList;
public class Test{
public static <T extends Comparable<T>> T minItem(ArrayList<T> l){
T y = l.get(0);
for(int i=1; i<l.size(); ++i){
T x = l.get(i);
if(x.compareTo(y) < 0) y = x;
}
return y;
}
public static void main(String[] args) throws IOException{
System.out.println("Enter a list of numbers, one on each line:");
//File file1 = new File("test.txt");
//Scanner =
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String input = reader.readLine();
ArrayList<Integer> nums = new ArrayList<Integer>();
while(input.length() > 0){
int x = Integer.parseInt(input);
nums.add(x);
input = reader.readLine();
}
System.out.println("nums: " + nums);
System.out.println("min: " + minItem(nums));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment