Created
January 13, 2023 16:48
-
-
Save ChicagoDev/c917a85d8bf23bd130dd41dd318dcb7a 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
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