Skip to content

Instantly share code, notes, and snippets.

@ChicagoDev
Created January 13, 2023 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ChicagoDev/c917a85d8bf23bd130dd41dd318dcb7a to your computer and use it in GitHub Desktop.
Save ChicagoDev/c917a85d8bf23bd130dd41dd318dcb7a to your computer and use it in GitHub Desktop.
import edu.princeton.cs.algs4.In;
import edu.princeton.cs.algs4.Quick;
public class Filtering34 {
public static void minMaxFilter() {
In in = new In();
int max = in.readInt();
int min = max;
while (in.hasNextLine()) {
int next = in.readInt();
if (next > max) {
max = next;
}
else if (next < min) {
min = next;
}
}
System.out.println("The maximum number is " + max);
System.out.println("The minimum number is " + min);
}
public static void medianFilter() {
In in = new In();
Integer[] numsComp = new Integer[100];
int[] nums = in.readAllInts();
for (int i = 0; i < 100; i++)
numsComp[i] = Integer.valueOf(nums[i]);
Quick.sort(numsComp);
int median = numsComp[50];
System.out.println("The median is " + median);
}
public static void main(String[] args) {
//minMaxFilter();
medianFilter();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment