Results 1 to 12 of 12

Thread: Something easy

  1. #1
    jeata is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default Something easy

    Hi
    I'm new to java and trying to solve this problem.

    Write e program, that read numbers from the keyboard until it receives a number<0. It then prints the sum of the numbers read before the 'stop'-number.

    So far I've got this

    Java Code:
    
    boolean repeat = true;
    		do
    		{
    			Scanner kb = new Scanner(System.in);
    			System.out.print("Enter: ");
    			int num = kb.nextInt();
    			if(num<0)
    			{
    			System.out.println("Negative number");
    			repeat = false;
    			}
    			if(num>=0)
    			{
    			 /*take num and store it in a value
    	           read value and add next num until stopped by negative value
    	         	*/
    			}
    
    		} while (repeat);


    If anyone has an idea, can you give me a hint.

    Thanks

  2. #2
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Yeah, do what it is hinted at in those comments?

  3. #3
    jeata is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    Yeah, do what it is hinted at in those comments?
    Yup, how do I do that ? That was my point in the first place :)

  4. #4
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    By typing in the editor?

    At least give it a try. We are not a homework service here.

  5. #5
    jeata is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    Quote Originally Posted by masijade View Post
    By typing in the editor?

    At least give it a try. We are not a homework service here.
    Yes I know, but I can't figure it out by myself, I think its not too hard for you

  6. #6
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, let's see what you tried, together with the compiler/error messages and/or a descritpion of the difference between the actual and expected results.

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

    Default

    Quote Originally Posted by masijade View Post
    Yeah, do what it is hinted at in those comments?
    You must be a rocket scientist ;-)

    kind regards,

    Jos

  8. #8
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Well, there is, normally, a light odor of Jet Fuel wherever I go. I can never seem to find it's source though. ;-)

  9. #9
    jeata is offline Member
    Join Date
    Oct 2010
    Posts
    33
    Rep Power
    0

    Default

    My point is that I don't know where to go from here on, i.e. I can't try anything, cause I have no idea what to do

  10. #10
    masijade is offline Senior Member
    Join Date
    Jun 2008
    Posts
    2,571
    Rep Power
    9

    Default

    Sorry, but if you can't even think of some kind of solution to at least try then you need to try a different vocation.

    In any case, create a variable and += it with the entered number. That is as much as you're going to get and much more than you should have needed. Now, try it.

  11. #11
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default

    Quote Originally Posted by jeata View Post
    My point is that I don't know where to go from here on, i.e. I can't try anything, cause I have no idea what to do
    Your best bet is to study your notes and the tutorials to gain enough of an understanding to at least be able to try. Til you bring yourself to this level, there's little help we have to offer.

  12. #12
    [RaIdEn] is offline Senior Member
    Join Date
    Oct 2009
    Location
    California,US
    Posts
    201
    Rep Power
    5

    Default

    actually the problem is not that difficult..we usually appreciate people that wrked really hard in solving it. Just reread how to store variables and manipulate them.

    Hint: try storing the initial value and keep adding it.

Similar Threads

  1. in need of help (easy)
    By fasck in forum New To Java
    Replies: 5
    Last Post: 12-30-2009, 10:45 PM
  2. Quick and Easy Job.
    By Scottyb in forum Jobs Offered
    Replies: 3
    Last Post: 08-11-2009, 03:48 PM
  3. how easy it is?
    By ron87 in forum New To Java
    Replies: 0
    Last Post: 04-01-2009, 06:36 PM
  4. Not so easy is it.
    By Roy Gardiner in forum Introductions
    Replies: 0
    Last Post: 10-24-2008, 04:59 PM
  5. What does this mean (Very Easy)
    By Zebra in forum New To Java
    Replies: 6
    Last Post: 05-01-2008, 01:46 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
  •