Results 1 to 2 of 2
  1. #1
    antidup is offline Member
    Join Date
    Aug 2011
    Posts
    4
    Rep Power
    0

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



    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.

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,352
    Blog Entries
    7
    Rep Power
    20

    Default 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:

    Java 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:

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

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Adding line numbers to code in output file
    By misterwebb in forum New To Java
    Replies: 2
    Last Post: 02-14-2011, 12:37 AM
  2. input 3 numbers output order least to greatest
    By rizowski in forum New To Java
    Replies: 8
    Last Post: 01-14-2011, 09:07 AM
  3. formatting numbers in output
    By andy3 in forum New To Java
    Replies: 3
    Last Post: 05-27-2010, 06:43 PM
  4. help with perfect squares
    By AmplifiedKid in forum New To Java
    Replies: 1
    Last Post: 09-19-2009, 07:44 PM
  5. Truncating decimal numbers in the output
    By gbade in forum New To Java
    Replies: 2
    Last Post: 11-21-2008, 06:25 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •