| View previous topic :: View next topic |
| Author |
Message |
Danny Gopie Guest
|
Posted: Mon Nov 22, 2004 4:16 pm Post subject: newbie |
|
|
Hello
i want to write a program that reads an integer between 0 and 1000 and
summarizes all the digits in the integer. For example, if an integer is 932,
the sum of all the digita is 14.
Does anyone knows how to do this?
Danny
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
|
| Back to top |
|
 |
Fahd Shariff Guest
|
Posted: Mon Nov 22, 2004 10:32 pm Post subject: Re: newbie |
|
|
you might have to convert the int to a string and then loop through the
chars in the String, converting each one into an int and adding:
int num = 932;
int sum = 0;
String s = Integer.toString(num);
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
int digit = Integer.parseInt(Character.toString(c));
sum += digit;
}
System.out.println(sum);
--
Fahd Shariff
http://www.fahdshariff.cjb.net
"Let the code do the talking... "
|
|
| Back to top |
|
 |
Steven T Abell Guest
|
Posted: Tue Nov 23, 2004 5:14 am Post subject: Re: newbie |
|
|
Danny Gopie wrote:
| Quote: | Hello
i want to write a program that reads an integer between 0 and 1000 and
summarizes all the digits in the integer. For example, if an integer is 932,
the sum of all the digita is 14.
Does anyone knows how to do this?
Danny
|
Danny, by any chance, are you a *student*?
And is this an *assignment*?
Steve
|
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Tue Nov 23, 2004 8:32 am Post subject: Re: newbie |
|
|
Danny Gopie wrote:
| Quote: | Hello
i want to write a program that reads an integer between 0 and 1000 and
summarizes all the digits in the integer. For example, if an integer is 932,
the sum of all the digita is 14.
|
This does not only awfully smell like homework, but it has absolutely
nothing to do with GUI development. Why do you post here?
/Thomas
--
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Tue Nov 23, 2004 9:31 am Post subject: Re: newbie |
|
|
On Tue, 23 Nov 2004 09:32:32 +0100, Thomas Weidenfeller wrote:
That's cool! (First time I'd noticed)
I'll have to update the link in my HTML version*. It also looks
like my copy is getting fairly out of date judging by a quick perusal
of the Q. #s listed in 'The GUI FAQ'.
I'll have to update mine 'real soon now'.
* I still want to retain the HTML version purely for the links/anchors.
[ BTW. Thank you for the good work. ]
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Tue Nov 23, 2004 12:18 pm Post subject: Re: newbie |
|
|
Andrew Thompson wrote:
uu.nl was the only faq archive which I could find which had already
picked up the faq. rtfm.mit.edu didn't pick it up (rtfm.mit.edu seems
to be having some problems in general, and I didn't bother trying to
find someone responsible for it). And faqs.org just takes the faqs from
rtfm.mit.edu.
So, when looking for a comp.lang.java.gui FAQ one might still end up
with PvdLs stalled and abandoned programming FAQ from 1999. Some sites
also carry an old FAQ from Elliotte Rusty Harold from 1997. Both authors
don't seem to care any more about the newsgroups (interestingly, both
went on to write Java books, so that might explain their lack of
interest in their FAQs).
| Quote: | * I still want to retain the HTML version purely for the links/anchors.
|
Either
http://www.cs.uu.nl/wais/html/na-dir/computer-lang/java/gui/faq.html
:-)
or see question Q1.7 of the FAQ ))
/Thomas
--
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Tue Nov 23, 2004 12:56 pm Post subject: Re: newbie |
|
|
On Tue, 23 Nov 2004 13:18:54 +0100, Thomas Weidenfeller wrote:
(GUI FAQ)
...and that's even better, but..
| Quote: | or see question Q1.7 of the FAQ ))
|
...ahh. I was browsing the text version in a window (amongst many)
had not noticed that yet.
If only text2html could recognize the index for what it is,
and insert appropriate links and anchors (but I suppose that
is expecting too much of a text -> HTML converter).
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Tue Nov 23, 2004 2:44 pm Post subject: OT: FAQ format (was: Re: newbie) |
|
|
Andrew Thompson wrote:
| Quote: | If only text2html could recognize the index for what it is,
and insert appropriate links and anchors (but I suppose that
is expecting too much of a text -> HTML converter).
|
It is supposed to insert anchors. At least if it manages to match the
headers, which requires to provide the tool with a regexp for matching
headers.
But if anything else fails, a short awk script like the following should
be a good start to link the TOC to the actual paragraphs:
/__/ { t++ }
t == 1 {
if($1 != "") {
$1 = $1
print "<a href="#" $1"">" $0 "</a>"
next
}
}
t > 1 && /^[ ]*Q*[1-9][0-9]*(.[1-9][0-9]*)* / {
print "<a name="" $1 ""></a>" $0
next
}
{ print }
/Thomas
--
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
|
|
| Back to top |
|
 |
Andrew Thompson Guest
|
Posted: Tue Nov 23, 2004 3:03 pm Post subject: Re: OT: FAQ format |
|
|
On Tue, 23 Nov 2004 15:44:58 +0100, Thomas Weidenfeller wrote:
| Quote: | But if anything else fails, a short awk ..
|
(eeek)
| Quote: | ..script like the following should
be a good start to link the TOC to the actual paragraphs:
|
OK. Thanks for the tip. I'll mull that over and perhaps drop
in to to an awk group to find how it is applied.
If I can get something workable, will you apply it to the HTML
version of the GUI FAQ you provide? That would be easiest, as
then I could simply link from my FAQ.
--
Andrew Thompson
http://www.PhySci.org/codes/ Web & IT Help
http://www.PhySci.org/ Open-source software suite
http://www.1point1C.org/ Science & Technology
http://www.LensEscapes.com/ Images that escape the mundane
|
|
| Back to top |
|
 |
Thomas Weidenfeller Guest
|
Posted: Tue Nov 23, 2004 3:12 pm Post subject: Re: OT: FAQ format |
|
|
Andrew Thompson wrote:
| Quote: | OK. Thanks for the tip. I'll mull that over and perhaps drop
in to to an awk group to find how it is applied.
|
Just run it with the file name as an argument Ok, and be careful in
awk groups. These people expect that you have read the awk documentation
before asking )
| Quote: | If I can get something workable, will you apply it to the HTML
version of the GUI FAQ you provide?
|
I didn't create that HTML version. Someone at that particular archive
did set up an automatic text to HTML conversion. I still just provide
the text version, via posting it to newsgroups.
/Thomas
--
ftp://ftp.cs.uu.nl/pub/NEWS.ANSWERS/computer-lang/java/gui/faq
|
|
| Back to top |
|
 |
|