23.11.2014 Views

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

Data Structures and Algorithms in Java[1].pdf - Fulvio Frisone

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Write a short <strong>Java</strong> function that takes an <strong>in</strong>teger n <strong>and</strong> returns the sum of all the<br />

<strong>in</strong>tegers smaller than n.<br />

R-1.11<br />

Write a short <strong>Java</strong> function that takes an <strong>in</strong>teger n <strong>and</strong> returns the sum of all the<br />

odd <strong>in</strong>tegers smaller than n.<br />

Creativity<br />

C-1.1<br />

Write a short <strong>Java</strong> function that takes an array of <strong>in</strong>t values <strong>and</strong> determ<strong>in</strong>es if<br />

there is a pair of numbers <strong>in</strong> the array whose product is odd.<br />

C-1.2<br />

Write a <strong>Java</strong> method that takes an array of <strong>in</strong>t values <strong>and</strong> determ<strong>in</strong>es if all the<br />

numbers are different from each other (that is, they are dist<strong>in</strong>ct).<br />

C-1.3<br />

Write a <strong>Java</strong> method that takes an array conta<strong>in</strong><strong>in</strong>g the set of all <strong>in</strong>tegers <strong>in</strong> the<br />

range 1 to 52 <strong>and</strong> shuffles it <strong>in</strong>to r<strong>and</strong>om order. Your method should output each<br />

possible order with equal probability.<br />

C-1.4<br />

Write a short <strong>Java</strong> program that outputs all possible str<strong>in</strong>gs formed by us<strong>in</strong>g the<br />

characters 'c', 'a', 'r', ' b', ' o', <strong>and</strong> 'n' exactly once.<br />

C-1.5<br />

Write a short <strong>Java</strong> program that takes all the l<strong>in</strong>es <strong>in</strong>put to st<strong>and</strong>ard <strong>in</strong>put <strong>and</strong><br />

writes them to st<strong>and</strong>ard output <strong>in</strong> reverse order. That is, each l<strong>in</strong>e is output <strong>in</strong> the<br />

correct order, but the order<strong>in</strong>g of the l<strong>in</strong>es is reversed.<br />

C-1.6<br />

Write a short <strong>Java</strong> program that takes two arrays a <strong>and</strong> b of length n stor<strong>in</strong>g <strong>in</strong>t<br />

values, <strong>and</strong> returns the dot product of a <strong>and</strong> b. That is, it returns an array c of<br />

length n such that c[i] = a[i] · b[i], for i = 0,… ,n − 1.<br />

Projects<br />

P-1.1<br />

86

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!