Skip to content
 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java-Lab-007

Java lab 7 practicing loops

PART 1: Practicing While Loops

  1. In the WhileLoops class, write a method named eoCount that contains a while loop that reads in integers from System.in, and counts the even and odd numbers separately.
  2. In the WhileLoops class, write a method named mean that contains a while loop that reads in integers from System.in and calculates the mean of the numbers entered.

PART 2: Practicing For Loops

  1. In the ForLoops class, create a method named forSum that calculates the sum 1+2+3+...+n where n is given as user input:

    • Example output will look like below:
    Number? 8
    The sum is 36
    
  2. In the ForLoops class, create a method named rangeSum that sums a range/interval of numbers, and prints the range. Your program should not care if the smaller or larger numbers are entered first:

    • Example output will look like below:
    Number? 8
    Number? 3
    The sum is: 33
    
    • The sum in the above example is the result of: 3 + 4 + 5 + 6 + 7 + 8
  3. In the ForLoops class, implement a method named factorial that calculates the factorial of a number read in from System.in:

    • e.g. 9 Factorial means: 9 * 8 * 7 * 6 * 5 * 4 * 3 * 2 * 1;
    • Example output will look like below:
    Number: 9
    Factorial: 362880
    

PART 3: Loop Refactoring

  1. In a class named ReWrites, rewrite the while loops in the sumRewrite method without the break condition and the boolean true in the parenthesis.
  2. In a class named ReWrites, rewrite the while loops in the avgRewrite method as a for loop instead of a while loop.

PART 4: Turn In

  • Make sure to use the Git tab at the bottom of IntelliJ to create a Feature1 feature branch
  • Commit and Push your running code back to your GitHub account
  • Issue a Pull request back to my Java-Lab-007 repo
  • Cut and Paste the Pull request URL into your Canvas assignment to turn it in.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages