Question: Task : Write and run java code for the following (similar to last slide or so in the Lecture 13 slides). See also the code

Task: Write and run java code for the following (similar to last slide or so in the Lecture 13 slides).

  • See also the code from what we did in class today: nested loops.txt

Write Java code to calculate and print the factorial for each line from 1 up to x (x is hard-coded to a value of your choice.)

  • For example, if x is equal to 4, it prints:
    • 1
    • 2
    • 6
    • 24

Link for the factorial: http://mathworld.wolfram.com/Factorial.html (Links to an external site.)

The code must use nested loops but in the following way:

it must use a while loop (running from 1 up to x) and must call a method to calculate the factorial:

  • method factorial() calculates and returns the factorial
  • takes int parameter, and returns int
  • must do the factorial calculation with a for loop

Your code must contain a comment with your own NAME.

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!