Quiz4_2010_sol - int value = my_method( a, a.length );

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
University of Ottawa Student name ………………. .………. .. School of IT and Engineering Student no . …………….………. .……. . ITI 1120 Quiz 4 Q1. [2 marks] What does the following Java code print? Circle one answer. public class Quiz4 { public static void main( String[] args ) { int [] a = {5, 3, 7, 2, 10, 6};
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: int value = my_method( a, a.length ); System.out.println(value); } public static int my_method( int x, int n) { int v; int previous; if (n == 1) { v = x[0]; } else { previous = my_method( x, n-1 ); if ( previous < x[n-1] ) { v = previous; } else { v = x[n-1]; } } return v; } } Answer: a. 2 c. 5 b. 10 d. 33...
View Full Document

This note was uploaded on 01/06/2011 for the course ITI 1120 taught by Professor Inkpen during the Fall '07 term at University of Ottawa.

Ask a homework question - tutors are online