# Lab2 - Java Programming Lab 2 Exercise 1 Final Zeros in a...

This preview shows pages 1–2. Sign up to view the full content.

Lab 2 Exercise 1: Final Zeros in a Factorial Examine the table of factorials at the end. You can see that starting with 5!, all the subsequent factorials end in a final flourish of zeros. Examine the pattern and then correct the following code so that it correctly computes the number of final zeros up to 625! – without actually computing these large factorials. a. How many final zeros are there in 20!, 25!, 50!, 100! 125! and 625! 20! ends with ………. zeros. 25! ends with .………. zeros. 50! ends with ………. zeros. 100! ends with ………. zeros. 125! ends with ………. zeros. 625! ends with 156 zeros. b. Correct this code which contains a logical error inside the for loop in the line that computes the quantity 'zeros'. Your code only need be valid up to and including the count of 625. Adjust the for loop controls to go from 1 to 625. Hint: The 5s determine everything. public class FinalZeros { public static void main(String[] args) { int count; int zeros; for(count=1; …………. . ; ………… ; ) // 1. Go from 1 to 625 { zeros = count/5; // 2. Correct this line System.out.println(count +"! ends in " + zeros + " zeros."); } //End of for loop. } //End of method main.

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 3

Lab2 - Java Programming Lab 2 Exercise 1 Final Zeros in a...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online