# Output all the numbers and their squares between 1 and 10.

• 10-17-2011, 05:26 PM
antidup
Output all the numbers and their squares between 1 and 10.
:(sweat):

Write a program that uses while loops to perform the following steps:
a. Promp the user to input two integers: firstNum and secondNum.(firstNum
must be less than secondNum.)
b. Output all the odd nummbers between firstNum and secondNum.
c. Output the sum of all even numbers between firstNum and secondNum.
d. Output all the numbers and their squares between 1 and 10.
e. Output the sum of the squares of all the odd numbers between firstNum and
secondNum.

I'm working on d and e, but i dont know how to show the square of the Output all the numbers and their squares between 1 and 10.
• 10-17-2011, 05:58 PM
JosAH
Re: Output all the numbers and their squares between 1 and 10.
You do know that i*i is the square of a number i, do you? You also know how to print both of them? Here's how:

Code:

` System.out.println(i+" "+i*i);`
You also know how to create a loop that iterates from 1 to 10, do you? Here's how:

Code:

`for (int i= 1; i <= 10; i++)`
It doesn't take rocket science to combine the two ...

kind regards,

Jos