/* Lab : Lab3 Day : Tuesday [ 12 Aug 08 ] Problem Number: 01 Problem Title : Finding largest devisor amongst 3,7 and 21 Theory : There are two things in this question 1. How to find whether a number x can devide y ? simple test the remainder obtained when y is devided by x. we can use % operator [ remainder is ( y % x ) ] if this remainder is zero then y is devisible by x 2. Out of three divisors which is the biggest Proceed in bottom up manner first chack whether the number is devided by 21 if not the chack whether the number is devided by 7 if still not devided then chack whether 3 can devide the number if not then report error "non of 3 7 21 can devide the number" Let us follow the instructions given in the problem */ class sol_lab3_prob01{ public static void main(String args[]) { // Declare and initialize a variable num of type int int num; num = 28; // done // first chack whether the number is devided by 21 if( (num % 21) == 0 ) { System.out.println("21 is the biggest number that devides " + num ); return; // exit the program, as biggest divisor is reported } // if not the chack whether the number is devided by 7 if( (num % 7) == 0 ) { System.out.println("7 is the biggest number that devides " + num ); return; // exit the program, as biggest divisor is reported } // if still not devided then chack whether 3 can devide the number if( (num % 3) == 0 ) { System.out.println("3 is the biggest number that devides " + num ); return; // exit the program, as biggest divisor is reported } // This statement will only execute of none of 21, 7 or 3 can devide num // print error message and exit System.out.println("none of 21, 7 or 3 can devide " + num ); } }