Section9Problems 3 - wri-te a method stutter that takes a...

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: . wri-te a method stutter that takes a stack containing a list of integers and that replaces every value in the stack with 2 of that value. For example, suppose a stack stores these values: bottom Then the [3, 1, L, 14, store J, I, 9] top these I, L4, va]-ues af ter 14, g, 9] the method terml-nates: stack [3, should 3, J, top Notice that you must preserve the original order. In the original list the 9 was at the top and wou.l-d have been popped f irst. rn the new stack the trwc 9's would be the first values popped from the stack. Your method is to take a parameter of type Stack<Integer>, lecture. Method stutter should take a single parameter: containing the List of integers to be stuttered. 9, Write a method countToBy that takes integer r rn, indicating how to count to ln znrd vr v au u c s o u t p u t example, Eo count, to 10 by 1 you'd say: countToBy which shouLd L, 2, 3, (10, 1); the 6, 7, following g, g, 10 the of following 4: call output: as described the stack in parameters n and m and that n in increments of m. For produce 4, 5, The increment does not indicates that we want countToBy which produces L, 5, g, (25, this 13, If, 4l ; have to be 1. For example, to count to 25 in increments output: 2I, 25 to start counting at 1. of 1 to m incl-usive. so with Z. So this calL: The f j.rst num.ber you instead count rt wil-l not always be possible should always be in the range to 30 by 4, you have to start countToBy (30, produces 2, this 6, 10, 4l ; if output: 14, 19, 22, 26, 3O Al-l output caLrs: should rt j-s possible appear on the that only same line. one number will be printed. For example, the forrowing // // O; // to to to complete complete countToBy (34, 5), System.out.println countToBy (3, 6) ; System.out.printfnO; countToBy (17 , 3) ; System.out.println shouLd 4, J O; the the lj-ne line 1ine of of of output output output compJ-ete the produce g, 5, L4, g, the Lg, 17, fol_Iowing 24, 74, 29, 77 34 output: 2, You must exactly reproduce the format shoul-d throw an rllegalArgumentException of the exampJ-es above. if eithei m or n is your method less than 1. ...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online