--- Begin Sum.java --1: //Sum.java 2: //solution to page 165 #8 3: 4: import java.util.Scanner; 5: 6: public class Sum{ 7: public static int sum (int n) 8: { 9: System.out.println("On this call n = " + n); 10: if (n==1) 11: return 1; 12: else return (n + sum(n-1)); 13: System.out.println("On return n = " + n); E: unreachable statement E: System.out.println("On return n = " + n); 14: E: E:
} missing return statement }
15: 16: public static void main(String[] args){ 17: int value; 18: Scanner valueIn = new Scanner(System.in); 19: 20: System.out.print("enter the value to sum to: "); 21: value = valueIn.nextInt(); 22: 23: System.out.println("the sum of the number 1-" + value + " is: " + sum(value)); 24: } 25: } --- End Sum.java ---
--- Begin Gcd.java --1: //Gcd.java 2: //CS 111 sample program to illustrate calculating the greatest common divisor 3: 4: /**public static int Gcd (int a, int b) 5: * pre condition ba 11: * error terminate if a or b = 0 12: */ 13:
3
14: /* test plan 15: goal input 16: valid 26, 8 > 1 17: boundary 125, 25 18: valid 1024, 36 > 2 19: boundary 36, 36 20: boundary 735, 16 factors other than 1 21: valid 24, -20 < 0 22: invalid 8, 26 23: invalid 4, 0 24: invalid 0,4 25: */ 26: 27: import java.util.Scanner; 28: 29: public class Gcd 30: { 31: 32: public static int gcdr(int a, int b) 33: { //precondition b=0 && r < BOARDSIZE && c >=0 && c < BOARDSIZE); 14: } 15: 16: private static boolean available(int r, int c) 17: { 18: return (board[r][c]== -1); 19: } 20: 21: private static boolean ktour (int r, int c, int moveNum) 22: { 23: int i, nr=0, nc=0; 24: 25: //System.out.println("movenum=" + moveNum); 26: //is spot acceptable 27: if (!onBoard(r,c) || !available(r,c)) return false; 28: 29: //record move 30: board[r][c]=moveNum; 31: 32: //done the whole board? 33: if (moveNum==BOARDSIZE*BOARDSIZE) return true; 34: 35: //pick next move 36: for (i=0;is, face=>f 37: { suit =s; 38: face = f; 39: } 40: 41: //accessors 42: public Suits suit () 43: {return suit;} // suit of the card 44: 45: public int face () 46: {return face;} // returns face value of card 47: 48: //Function to display card 49: public void printcard() 50: { 51: System.out.print("The card is "); 52: if (face > 1 && face =1 && number