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:
1) Create a main() method with a switch statement that calls either a sum() OR factorial() method, depending on what sel
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am