Function Worksheet Answers

1.   7


2.   2
     6
     21
     88


3.   public static double postage (int ounces, int pounds, int costperounce) {
         ounces = ounces + pounds * 16;
         return (ounces * costperounce);
     }


4.   System.out.println("Enter package weight in pounds and ounces: ");
     pounds = keyin.nextInt();
     ounces = keyin.nextInt();
     System.out.println("Enter mailing cost per ounce: ");
     ouncecost = keyin.nextInt();
     mailcost = postage(ounces,pounds,ouncecost);
     System.out.println("The cost to mail this package is: " + mailcost);


5.   public static void checkeven(int num1,int num2,int num3) {
        if (num1 % 2 == 0 && num2 % 2 == 0 && num3 % 2 == 0)
           System.out.println("YES");
        else
           System.out.println("NO");
     }


6.   System.out.println("Enter three numbers: ");
     n1 = keyin.nextInt();
     n2 = keyin.nextInt();
     n3 = keyin.nextInt();
     checkeven(n1,n2,n3);


7.   public static boolean checkeven(int num1,int num2,int num3) {
        if (num1 % 2 == 0 && num2 % 2 == 0 && num3 % 2 == 0)
           return true;
        else
           return false;
     }


8.   System.out.println("Enter three numbers: ");
     n1 = keyin.nextInt();
     n2 = keyin.nextInt();
     n3 = keyin.nextInt();
     result = checkeven(n1,n2,n3);
     if (result)       // same as if (result == true)
        System.out.println("YES");
     else
        System.out.println("NO");


Email Me | Office Hours | My Home Page | Department Home | MCC Home Page

© Copyright Emmi Schatz 2013