Section9Problems 4 - 10. Write a method printRange x and y...

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

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 10. Write a method printRange x and y and t.hat pri-nts that takes parameters integers sequential The f irst between x and y inclus j:ve. ha.l-f should be ( " > " ) separating printed with the greater-than consecut j-ve values. The second hal-f should be printed with the less-than character ("<') separating consecutive values. For example, the following call-s: (1, 9l; printRange System.out.prj-nt1nO; (8, 20) ; printRange System.out.println O; (-8, -8); printRange System.out.print:-n O; produce the // // // to to to complete the line line line of of of output output output . complet,e the complete the should following output: l>2>3>4>5<6<1<g<g B > 9 > 10 -8 Notice in the first that output, 5 is in the middle with the numbers befor= it separated by greater-than and the numbers after it separated by -l-ess-than. In the second output , L4 is in the middle with numbers before it by greater-than separated and numbers after it separated by Less-than. The third output has no separators because that range includes one number. When there are two values in the middle of the range, those shouJ-d be separated by a dash. For example, these call_s: (1, 10); printRange System.out.printlnO; (13, 14) , printRange System.out.pri-ntln O; should produce the followinq to to two values // // complete complete the the Iine line of of output output output: 1>2>3>4>5-6<1<g<g<10 13 14 You must exactly reproduce the throw an IllegalArgumentException 11. format of these examples. if x is greater than y. The method shoulc Write a method evens that takes an integer inraaar eormed by removing the odd digits EVENS EVENS parameter n and that returns from n. For exampl_e: th evens 8342116) returns 8426 4109) returns 4O 8) returns 8 even also -42 -60 are no even zeror ds in: digits other be negative, than zero as in: is passed to the If a negative number with method, the result should evens(-34512) returns evens (-163505) returns Any leading zeros digits than other in the result should be ignored and if there zero in the number, the method should return evens(3052) returns 2 evens(7010496) returns 46 evens (35179) returns 0 evens(5307) returns O evens(7) returns 0 ...
View Full Document

This note was uploaded on 11/03/2009 for the course CSE 143 taught by Professor Sr during the Spring '08 term at University of Washington.

Ask a homework question - tutors are online