Question: a) Create a program that will ask the user for a positive integer and then will use a for loop to display the positive integers

a) Create a program that will ask the user for a positive integer and then will use a for loop to display the positive integers in ascending order starting at 1 ending at the given input. Each number should be followed by a comma and a space except for the last value.

b) Add a new method to your program within the same class. This method will receive a positive integer as an argument and use a While loop to create a string that is the positive integers in ascending order starting at 1 and ending at the given input. Each number should be followed by a comma and a space except for the last value. The method will then return that string.

Your main method should call this method passing in the user input and the outputting the returned string. You should output a heading above each part so it is clear which part of the output comes from the for loop and which comes from the method call.

c) Create the new class within the same project that will receive a positive integer as an argument and use a while loop to output the positive integers in ascending order starting at 1 and ending at the given input. Each number should be followed by a comma and a space except for the last value. This will not return any values as the output commands should be within this method.

Your main method should call this method passing in the user input. You should output a heading above each part so it is clear which part of the output comes from the for loop, which comes from the method call within the class, and which comes from a method call from the external class.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!