Docsity

Introduction to Computing and Programming - Looplab.java | CSCI 1301, Lab Reports of Computer Science

Toggle sidebar
bg1
Csci 1301, Lab 6
2007.01.31/02.04
LoopLab.java
1
In this lab you’ll be getting familiar with loops. Part 2 will involve a simple print
statement. Part 3 will require you to use an if statement (or some clever coding). Parts
3 and 4 will get you started using expressions inside a loop.
1. Input two int values from the user. These will serve as upper and lower bounds
for a loop.
2. Use a while loop to print out all values greater than or equal to the lower
bound but less than the upper bound. Use the print statement and the ā€˜\t’
character to avoid printing each number on its own line.
3. Use a for loop to do almost the same thing. Except only print out the even
values. Hint: All even values have a remainder of 0 when divided by 2.
4. Finally, use a loop of your choice to print out the squares of all of the numbers
between 1 and 100. Remember, don’t ā€œhard-codeā€ in any values here. Create
constants (ā€œfinal variablesā€) instead.

Partial preview of the text

Download Introduction to Computing and Programming - Looplab.java | CSCI 1301 and more Lab Reports Computer Science in PDF only on Docsity!

Csci 1301, Lab 6 2007.01.31/02. LoopLab.java

In this lab you’ll be getting familiar with loops. Part 2 will involve a simple print statement. Part 3 will require you to use an if statement (or some clever coding). Parts 3 and 4 will get you started using expressions inside a loop.

  1. Input two int values from the user. These will serve as upper and lower bounds for a loop.
  2. Use a while loop to print out all values greater than or equal to the lower bound but less than the upper bound. Use the print statement and the ā€˜\t’ character to avoid printing each number on its own line.
  3. Use a for loop to do almost the same thing. Except only print out the even values. Hint: All even values have a remainder of 0 when divided by 2.
  4. Finally, use a loop of your choice to print out the squares of all of the numbers between 1 and 100. Remember, don’t ā€œhard-codeā€ in any values here. Create constants (ā€œfinal variablesā€) instead.