| Instructor |
Course: Java
- While Loop Program Work |
| Debra
Butera |
Class: While1
Create a program that uses a While
loop from 1 to 10 and prints each number
Input:
None
Output:
1
2
3
4
5
6
7
8
9
10
|
| |
Class: While2
Create a program that uses a While loop from 100 to
90 and prints out each number in descending order.
Input:
None
Output:
100
99
98
97
96
.
.
90
|
| |
Class: While3
Create a program that uses a While loop from 100 to
50 and prints out each number in descending order by
5.
Input:
None
Output:
100
95
90
85
.
.
50
|
| |
Class: While4
Create a program that uses a While
loop to count backwards by 5 starting with 50 while
the number is not equal to 5.
Input:
none
Output:
50
45
40
...
15
10
|
| |
Class: While5
Create a program that uses a while
loop to find the product of each number between 50 and
100 multiplied by 2 while the numbers are incremented
by 10.
Input:
None.
Output:
100
120
140
160
180
200
|
| |
Class: While6
Create a program that uses a While
loop to find the squares of all the numbers from the
1 to 10.
Input:
None.
Output:
square of each number
|
| |
Class: While7
Make your loop flexible.
Create a program that uses a While
loop to find the sum of all the numbers from the input
starting value to the input ending value.
Input:
starting value
ending value (must be greater than the starting value)
Output:
Print all the first sum over 50 and leave the loop.
|
| |
Class: While8
Create a program that uses a while
loop to print 10 random integers between 1 and 10 inclusive.
For random class information, see pg 94 in textbook.
Input:
none
Output:
10 random numbers
|
| |
Class: While9
String x = "Hello";
Create a program that uses a While
loop, length and substring to print each letter of the
string on a separate line.
Input:
none
Output:
H
e
l
l
o
|
| |
Class: While10
Create a program that uses a While
loop to determine which numbers between 1 and 20 are
even and which are odd. Use the modulus operator to
accomplish this. See pg 59 in textbook.
Input:
x number of grades
Output:
average grade
|
| |
Class: While11
Make your loop sentinel controlled.
Create a program that uses a While
loop to reads in and sums grades until a -1 (a sentinel)
in input.
Input:
x number of grades
Output:
average grade
|
| Extra
Credit: |
Class: WhileExCr1
Change the While9 program above: make it more flexible.
This program should ask the user or a word rather than
using the given string "Hello".
|