![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Newbie
Join Date: Feb 2005
Posts: 1
Rep Power: 0
![]() |
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. |
|
|
|
|
|
#2 |
|
Professional Programmer
|
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
}
} .. good luckalso, 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. |
|
|
|
|
|
#3 | |
|
The Supreme Ruler
![]() Join Date: May 2004
Location: Houston
Posts: 1,476
Rep Power: 6
![]() |
Quote:
__________________
"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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|