Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Feb 14th, 2005, 1:50 PM   #1
evnp85
Newbie
 
Join Date: Feb 2005
Posts: 1
Rep Power: 0 evnp85 is on a distinguished road
Need help with homework

I am new to writing in Java. I've been slacking probably more than I should be, and I have a small project that is due on Thursday for my class. Currently, I know how to write in C++ and C++ only. If someone could help me in writing the simple code for my project, that would be great.

The program is simple. It should allow a user to input a string of digits, and then output the sum of those digits.

For example; the user inputs 3563
the program would then output 17 (3+5+6+3)

Thanks for any help.
evnp85 is offline   Reply With Quote
Old Feb 14th, 2005, 2:18 PM   #2
xavier
Professional Programmer
 
xavier's Avatar
 
Join Date: Oct 2004
Location: .ro
Posts: 383
Rep Power: 4 xavier is on a distinguished road
Send a message via Yahoo to xavier
well .... the program starts with:
class name{
     public static void main (String args[]){
         int n=Integer.parseInt(args[0]);
          int S=0; // it's the sum of digits  ..... 
    // u declare some other variables ... the same way .. if you need .... 

          //u do your thing, if u know in c++ .. it's the same in java

          System.out.println(S);// print the sum
}
}
that shouwld be about all ..... show us the code if u can't crack it .. good luck

also, the name of the file has to be exactly the same as the name of the class
__________________
Don't take life too seriously, it's not permanent !

Last edited by xavier; Feb 14th, 2005 at 2:22 PM.
xavier is offline   Reply With Quote
Old Feb 14th, 2005, 3:05 PM   #3
Mjordan2nd
The Supreme Ruler
 
Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6 Mjordan2nd is on a distinguished road
Quote:
Originally Posted by evnp85
I am new to writing in Java. I've been slacking probably more than I should be, and I have a small project that is due on Thursday for my class. Currently, I know how to write in C++ and C++ only. If someone could help me in writing the simple code for my project, that would be great.

The program is simple. It should allow a user to input a string of digits, and then output the sum of those digits.

For example; the user inputs 3563
the program would then output 17 (3+5+6+3)

Thanks for any help.
There are many different ways to go about doing what you just described. Show us what you've tried, and we'll help you correct it.
__________________
"Every gun that is made, every warship launched, every rocket signifies, in the final sense, a theft from those who hunger and are not fed, from those who are cold and are not clothed. The world in arms is not spending money alone. It is spending the sweat of its laborers, the genius of its scientists, the hopes of its children." - Dwight D. Eisenhower
Mjordan2nd is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:09 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC