
Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!

public static int numberAncestors(Rhino r) { int num= 0; if (r.father != null ) num= num + 1 + numberAncestors(r.father); if (r.mother != null ) num= num + 1 + numberAncestors(r.mother); return num; } 2a. 5 instances of Box are created: 4 horizontal ones and 1 vertical one. 2b. 4*4 buttons are created. **2c.
public static boolean** isTridiagonal(int[][] m) { for ( int k= 0; k != m.length; k= k+1) { // return false if row k contains a non-zero // where it should have a 0. for ( int i= 0; i != m.length; i= i+1) { if (i != k-1 && i != k && i != k+1 && m[k][i] != 0) { return false ; } } } return true ; } 4a. /** Constructor: integer i in Mod n arithmetic Precondition: n > 1. There are no restrictions on i./ public Mod( int i, int modulus) { this .i= i; this .modulus= modulus; modularize(); } /* If r1 and r2 do not have the same modulus, return null; otherwise return r1 + r2 / public static Mod add(Mod r1, Mod r2) { if (r1.modulus != r2.modulus) return null ; return new Mod(r1.i + r2.i, r1.modulus); } /* = r is a non-null Mod with the same modulus and integer as this one */ public boolean equals(Object ob) { return ob != null && ob instanceof Mod && i == ((ob)r).i && modulus == ((ob)r).modulus; }