Docsity

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

Toggle sidebar
bg1
Csci 1301, Lab 4
2008.06.18
LoopLab.java
1
Lab 4 will initially look very much like the loops we’ve written in class. We’ll
spice it up by nesting some conditionals inside of the later 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. Use a loop of your choice to print out the squares of all of the perfect squares of
numbers between 1 and 100. (E.g. 1, 4, 9, …, 10000) Remember, don’t ā€œhard-
codeā€ in any values here. Create constants (ā€œfinal variablesā€) instead. Also, just to
make it tricky, print out ten values, tab-separated, on each line.

Partial preview of the text

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

Csci 1301, Lab 4 2008.06. LoopLab.java

Lab 4 will initially look very much like the loops we’ve written in class. We’ll spice it up by nesting some conditionals inside of the later 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. Use a loop of your choice to print out the squares of all of the perfect squares of numbers between 1 and 100. (E.g. 1, 4, 9, …, 10000) Remember, don’t ā€œhard- codeā€ in any values here. Create constants (ā€œfinal variablesā€) instead. Also, just to make it tricky, print out ten values, tab-separated, on each line.