1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what sel

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what sel

Post by answerhappygod »

1) Create a main() method with a switch statement that callseither a sum() OR factorial() method, depending on what selectionthe user of the program makes - ask the user to enter a selection(with System.out.println()), create a Scanner then read the user'sinput with a call to the Scanner.next() method, then call theappropriate method in a switch (the String that was read from thecall to Scanner.next() should be what you use as your switchcondition).
2) Create a method, sum(), to include a FOR loop that will:
Get a scanner and input a number from the keyboard in main().The method will take one parameter and calculate the sum up to thatnumber. For example, if you pass 5, it it will calculate 1+2+3+4+5and will return it back to main() method.
3) Create another method, factorial(), and repeatwhat was done for the sum() method above but compute the productinstead.
Requirements/Rules:
Input:
Processing:
Output:
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply