Question
Assignment 11.1: Valentine Loop (10 pts) Create a new Java file Valentine.java. Write a program that uses a while loop to print the numbers from
Assignment 11.1: Valentine Loop (10 pts)
- Create a new Java file Valentine.java.
- Write a program that uses a while loop to print the numbers from 1 to 150, with each number printed on its own line.
- For multiples of 3, print "Roses are red." instead of the number.
- For the multiples of 5, print "Violets are blue." instead of the number.
- For numbers which are multiples of both 3 and 5, print "Sugar is sweet, and so are you!".
- You must use a while loop for full credit.
- Hint: Test for numbers that are multiples of both 3 and 5 first.
- When you are finished, and your output looks identical to mine, upload your assignment to Canvas.
Your Output Should Look Identical to the Following:
1 2 Roses are red. 4 Violets are blue. Roses are red. 7 8 Roses are red. Violets are blue. 11 Roses are red. 13 14 Sugar is sweet, and so are you! 16 17 Roses are red. 19 Violets are blue. Roses are red. 22 23 Roses are red. Violets are blue. 26 Roses are red. 28 29 Sugar is sweet, and so are you! 31.
.
.
.
.
.
.
94 Violets are blue. Roses are red. 97 98 Roses are red. Violets are blue. 101 Roses are red. 103 104 Sugar is sweet, and so are you! 106 107 Roses are red. 109 Violets are blue. Roses are red. 112 113 Roses are red. Violets are blue. 116 Roses are red. 118 119 Sugar is sweet, and so are you! 121 122 Roses are red. 124 Violets are blue. Roses are red. 127 128 Roses are red. Violets are blue. 131 Roses are red. 133 134 Sugar is sweet, and so are you! 136 137 Roses are red. 139 Violets are blue. Roses are red. 142 143 Roses are red. Violets are blue. 146 Roses are red. 148 149 Sugar is sweet, and so are you!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started