Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: im dying here..on a simple code

  1. #1
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Exclamation im dying here..on a simple code

    the question says
    1. Write a program called SumDigits that obtains an integer from the user and then sums the digits. The program should use the remainder and integer division operators.

    i understand the question but i dont get how to do it...could anyone help me? please?


  2. #2
    Member
    Join Date
    Jul 2010
    Location
    Washington, USA
    Posts
    307
    Thanks
    16
    Thanked 43 Times in 39 Posts

    Default Re: im dying here..on a simple code

    int x = 15; //number to sum
    int sum = 0;
    	while(x > 0)
    	{
    		sum += x%10;
    		x /= 10;	
    	}			
    	System.out.println(sum);
    As for the user input, you should be able to do it yourself.
    All I did was a quick google search and I found the answer. Source http://www.dreamincode.net/code/snippet2727.htm

  3. The Following User Says Thank You to Brt93yoda For This Useful Post:

    Jason (September 28th, 2010)

  4. #3
    Forum VIP
    Join Date
    Jul 2010
    Posts
    1,619
    Thanks
    25
    Thanked 322 Times in 300 Posts

    Default Re: im dying here..on a simple code

    Ok, well we help step you through it, but not do it for you. So, I will provide you with the questions you need to ask yourself. Tell us what you know about each of these questions and provide code snippets and code examples for us to work with and help you better understand. Here are the questions (some are very basic, but are important to both creating the program and for us to gauge how much you already know):

    1) How do I set up a program?
    2) How do I prompt the user?
    3) How do I receive and process a response from the user?
    4) How do I sum integers?
    5) How do I get a remainder?
    6) How do I divide integers?
    7) How do I return the results to the user?

    Answer as many of these 7 questions as you can, in as much detail as you can. We can then help you with the scraps that you need to pick up.

  5. #4
    Junior Member
    Join Date
    Sep 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: im dying here..on a simple code

    Quote Originally Posted by Brt93yoda View Post
    int x = 15; //number to sum
    int sum = 0;
    	while(x > 0)
    	{
    		sum += x%10;
    		x /= 10;	
    	}			
    	System.out.println(sum);
    As for the user input, you should be able to do it yourself.
    All I did was a quick google search and I found the answer. Source http://www.dreamincode.net/code/snippet2727.htm
    thanks alot...i really really appreciate it <3

Similar Threads

  1. [SOLVED] "possible loss of precision", except not, code doesn't work, simple question
    By Perd1t1on in forum What's Wrong With My Code?
    Replies: 2
    Last Post: July 24th, 2010, 07:11 PM
  2. urgent simple help for a very simple program
    By albukhari87 in forum Java Applets
    Replies: 4
    Last Post: June 5th, 2010, 03:43 PM
  3. Dying PC, I might need someones help
    By FluectFuercig in forum The Cafe
    Replies: 7
    Last Post: March 2nd, 2010, 07:56 AM
  4. not so simple, simple swing question box
    By wolfgar in forum AWT / Java Swing
    Replies: 2
    Last Post: November 20th, 2009, 02:47 AM
  5. Help! how would you code these simple games?
    By makarov in forum Java Applets
    Replies: 1
    Last Post: November 14th, 2009, 11:31 AM