Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / October 2007

Tip: Looking for answers? Try searching our database.

Sum of all even integers

Thread view: 
ericcc - 09 Oct 2007 22:27 GMT
"Use WHILE. Write an application that asks the user to input integers,
calculates the sum of all even integers, and displays the result.
Allow the user to decide when to quit."

So far this is what I have:
import java.util.Scanner;

public class Sum
{
   public static void main(String[] args)
   {
       // declare and initialize variables
       int count;
       double total, sum;
       String integer;

       count = 0;
       total = 0;
       String another = "y";

       Scanner in = new Scanner(System.in);

       // while the user inputs yes to continue
       while ((another.toUpperCase()).equals("Y"))
       {
           // Ask the user to input the integer
           System.out.println("Enter an integer: ");
           integer = in.next();

           // help!

           // check if the user wants to continue
           System.out.println("Would you like to enter another
integer (y/n): ");
           another = in.next();
       }

       // calculate the sum
       // help!

       // display the average
       System.out.println("The sum of all even integers is " + sum);
   }
}
Lew - 10 Oct 2007 00:41 GMT
> "Use WHILE. Write an application that asks the user to input integers,
> calculates the sum of all even integers, and displays the result.
> Allow the user to decide when to quit."

Check out Roedy's answers in the other group to which you multiposted,
comp.lang.java.help.

Please do not multipost.  It fragments the conversation and makes it
annoyingly hard to follow.  If you really, really, really, really feel that
you absolutely cannot live without reaching multiple groups (even though
they're mostly the same people), then cross-post, preferably setting one of
the groups as your followup (a.k.a., "f/u" or "f-u" in some folks'
abbreviation lexicon).

Signature

Lew

ericcc - 10 Oct 2007 00:49 GMT
> > "Use WHILE. Write an application that asks the user to input integers,
> > calculates the sum of all even integers, and displays the result.
[quoted text clipped - 12 lines]
> --
> Lew

sorry for multiposting. after i posted in this one i discovered
comp.lang.java.help and thought my question should go in there instead
of in here.
Lew - 10 Oct 2007 03:56 GMT
> sorry for multiposting. after i posted in this one i discovered
> comp.lang.java.help and thought my question should go in there instead
> of in here.

Just to help you out, here's an idea.  Instead of starting a new thread on an
extant question (obviously not relevant for something really, really old),
continue the thread with cross-posting, as I did to unify your multiposts.

Even that is likely not to be very helpful, really.  Mostly the same people
read and answer questions in both clj.help and clj.programming, so by
multiposting you are actually discouraging the most knowledgeable people from
wanting to help.  By sticking with one group or the other, you're getting
substantially the same audience.

It's a good idea to read up on Usenet etiquette, a.k.a., "netiquette".  Among
other resources is the "comp.lang.java.{help,programmer} - what they're for
(mini-FAQ 2006-03-31)" message, reposted every few days in both groups so that
everyone has no excuse not to read it.  (Notice that it subsumes both the
clj.help and clj.programmer groups, a big, fat clue that they're related.)

Among other things, it advises:
> Don't cross-post between these groups and c.l.j.programmer or .help -- it just
> wastes the time of people reading the general groups.

It also mentions, and links to explanations for, SSCCE (RTFM)
<http://www.physci.org/codes/sscce.jsp>
and
> Before posting read Jon Skeet's "How to get answers on the comp.lang.java.*
> newsgroups" at
<http://www.pobox.com/~skeet/java/newsgroups.html>

The first sentence in that last link after the introductory paragraph is:
> Don't multi-post.

RTFM.

Signature

Lew



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.