Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums

Go Back   Code Forums > Application and Web Development > Java

Reply
 
LinkBack Thread Tools Display Modes
Old 10-19-2005, 12:54 PM   #1 (permalink)
ZimbuTM
Registered User
 
Join Date: Sep 2005
Posts: 10
ZimbuTM is on a distinguished road
Is it necessary to use strings for this assignment?

We have to prompt the user for two integers m and n, then compute and print the sum of the digits of integers m TO n. Example:

1985 1991

1985 - 23
1986 - 24
1987 - 25
1988 - 26
1989 - 27
1990 - 19
1991 - 20

Will it be necessary to convert the integers to string and then use the charAt() method? Is there a simpler way to do this?

Just looking for a hint, no solutions please. Thanks.
ZimbuTM is offline   Reply With Quote
Old 10-19-2005, 01:43 PM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,166
Belisarius is on a distinguished road
The charAt() isn't really a good idea, as if the user inputs an extra space by accident, or doesn't use two 4 digit numbers, it'll cause problems. I'd suggest StringTokenizer.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 10-19-2005, 02:01 PM   #3 (permalink)
ZimbuTM
Registered User
 
Join Date: Sep 2005
Posts: 10
ZimbuTM is on a distinguished road
I'll look into that, although we haven't learned about it yet.
ZimbuTM is offline   Reply With Quote
Old 10-19-2005, 05:20 PM   #4 (permalink)
ZimbuTM
Registered User
 
Join Date: Sep 2005
Posts: 10
ZimbuTM is on a distinguished road
Is it possible to do this using only integers and no strings?
ZimbuTM is offline   Reply With Quote
Reply

Bookmarks

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
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help with an assignment ZimbuTM Java 9 09-23-2005 02:33 AM
Looping search strings. phill2000star PHP 4 07-18-2005 04:37 PM
NEED HELP on card assignment marina Standard C, C++ 9 05-03-2005 07:42 AM
Help in my assignment plZ VaMpIrE Standard C, C++ 1 12-08-2004 01:15 AM
New Tutorials: ASP Strings, and Visual Studio/VB.NET sde Code Newbie News 0 03-25-2004 06:37 PM


All times are GMT -8. The time now is 01:45 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting