Unformatted text preview: b. Write n as a parameter a method writeChars takes an integer and that that writes The middle character out n characters as follows. of the output (rr*rr). should always be an asterisk If you are asked to write out an even in the middLe. number of characters, then there wil-l be two asterisks ( " <') . (s ) you shou]-d write Bef ore the asterisk characters out Iess-than (">"). you should write After characters the asterisk(s) out greater-than You should write l-ine of output, al-l of the characters on a single For example, the following calfs: (5); writeChars wri-teChars (B); System.out.printlnO; Would produce
<<i>> // to complete the Iine of output the following output: If your method is passed 1 or 2 as an argument, it should write Your method should throw an IllegalArgumentException asterisks. value less than 1. 1. out if just passed , Write a method printTwos that takes an integer n as a parameter and that prints an expressj-on composed of a single odd number multipli-ed by twos tha is equal to n. The twos should surround the odd number with an equal number For example, of Lwos on either side if possible. the call: printTwos should produce 2*2*5*2*2 If the appear has an odd number of expression at the front of the expression. ( 96) ; the foLlowing output: twos, then the "extra" For example, the call: two shou1d (80); the f ol-l-owing output: printTwos should produce 2*2*2*3*2*2 If the number possible that calIs: it is odd to begin with, It is shouLd simply be printed. the odd number to print wiII For example, be 1. the following printTwos (1) ; System.out.printJ-n printTwos (2) ; System.out.println printTwos(32); System.out.printl-n shou.l-d produce the O; O; Ot // // // to to to complete complete complete the the the l-ine l-ine l-ine of of of output output output f ollowing output: t*1
2*2*2*1*2*2 You must exactly reproduce the format should throw an IllegalArgumentException of Your method the examples above. if passed a val-ue less than 1. ...
View Full Document
- Spring '08
- Multiplication, English-language films, Subroutine, ASCII, printTwos