# Java: Method Exercises 3

Name: _________________________________

What is the output from this program?

      1
      2
      3
      4
      5
      6
      7
      8
      9
     10
     11
     12
     13
     14
     15
     16
     17
     18
     19
     20
     21
     22
     23
     24
     25
     26
     27
     28
     29
     30
     31
     32
     33
     34
     35
     36
     37
     38
     39
     40
     41
     42
     43
     44
     45
     46
     47
     48
    // methods/exercises/MethodExercises3 - What is the output?
    // Fred Swartz

    import javax.swing.*;

    class MethodExercises3 {
        public static void main(String[] args) {
            int n = 77;

            output("n = ", n);
            n = signum(7);
            output(n);
            output("Ans 3 =  ", doIt(2, 100));
            output("Ans 5 =  ", doIt(200, 200));
            output("Ans 5 =  ", doIt(100, 2));

            System.exit(0);
        }

        static void output(int i) {
            output("Result = ", i);
        }

        static void output(String message, int i) {
            JOptionPane.showMessageDialog(null, message + i);
        }

        static int signum(int a) {
            int result;
            if (a < 0) {
                result = -1;
            } else if (a > 0) {
                result = 1;
            } else {
                result = 0;
            }
            return result;
        }

        static int doIt(int x, int y) {
            int result;
            if (x < y) {
                return signum(y - x);
            } else {
                return Math.max(x, y);
            }
        }
    }