|
midterm
Nov 13, 2001 22:27:34 GMT -5
Post by Sylph on Nov 13, 2001 22:27:34 GMT -5
i figured out alternate solutions to question 1 of Brutal_Chicken's midterm. the first one was right when i practise-wrote the test (calmed down); the second one was wrong, so i fixed it. i tested these by actually compiling & running them. import java.io.*; public class Q1a { public static void main (String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int num = 100; int biggest = 0; while (num != 0){ num = Integer.parseInt(in.readLine()); if (num > biggest){ biggest = num; } } System.out.println(biggest); } } import java.io.*; public class Q1b { public static void main (String[] args) throws IOException { BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); int num = -1; int smallest = Integer.MAX_VALUE; while (num != 0){ num = Integer.parseInt(in.readLine()); if (num < smallest && num > 0){ smallest = num; } } if (smallest == 0){ System.out.println("No positive numbers read"); } else { System.out.println(smallest); } } }
|
|
|
midterm
Nov 14, 2001 7:27:49 GMT -5
Post by Brutal_Chicken on Nov 14, 2001 7:27:49 GMT -5
My midterm?!? Believe me if it was mine it'd be half a page with one dumbass question and the curve would be applied! ;D
|
|