Results 1 to 2 of 2
- 10-17-2011, 05:26 PM #1
Member
- Join Date
- Aug 2011
- Posts
- 4
- Rep Power
- 0
Output all the numbers and their squares between 1 and 10.
.gif)
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 #2
- Join Date
- Sep 2008
- Location
- Voorschoten, the Netherlands
- Posts
- 11,604
- Blog Entries
- 7
- Rep Power
- 17
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:
You also know how to create a loop that iterates from 1 to 10, do you? Here's how:Java Code:System.out.println(i+" "+i*i);
It doesn't take rocket science to combine the two ...Java Code:for (int i= 1; i <= 10; i++)
kind regards,
JosWhen people rob a bank they get a penalty; when banks rob people they get a bonus.
Similar Threads
-
Adding line numbers to code in output file
By misterwebb in forum New To JavaReplies: 2Last Post: 02-14-2011, 12:37 AM -
input 3 numbers output order least to greatest
By rizowski in forum New To JavaReplies: 8Last Post: 01-14-2011, 09:07 AM -
formatting numbers in output
By andy3 in forum New To JavaReplies: 3Last Post: 05-27-2010, 06:43 PM -
help with perfect squares
By AmplifiedKid in forum New To JavaReplies: 1Last Post: 09-19-2009, 07:44 PM -
Truncating decimal numbers in the output
By gbade in forum New To JavaReplies: 2Last Post: 11-21-2008, 06:25 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks