The Artima Developer Community
Sponsored Link

Java Answers Forum
help~!!!

17 replies on 2 pages. Most recent reply: Sep 11, 2003 3:09 AM by mausam

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 17 replies on 2 pages [ « | 1 2 ]
Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: help~!!! Posted: Sep 10, 2003 8:32 PM
Reply to this message Reply
Advertisement
Matt,

Very good technique indeed :-)

I like it.

gratiartis

Posts: 8
Nickname: gratiartis
Registered: Sep, 2003

Re: help~!!! Posted: Sep 11, 2003 3:00 AM
Reply to this message Reply
> Correction boss :
> Use
> } else if ( digit % 2 == 0 ) {

Hehe ... that'll teach me to test code before I post it ;)

> Moreover this can take any string like "abc"

I did think of that, but I was more interested in showing how to get at each digit in the String. So I didn't bother with any error handling. As mentioned elsewhere in the thread, I also didn't want to provide something that could be handed in as a homework assignment without doing quite a bit of work on it!

I'm not sure of what's the most efficient way to check the validity of the input. As you showed, just trying to instantiate an Integer seems the simplest way of doing it. Otherwise for each digit, you could always do (digit >= 0 && digit <= 9). Or for each char, before getting the number value, you could just do (char >= '0' && char <= '9'). Some kind of exception would be thrown if it's out of the range. Anyone else got any thoughts on this? I was never much of an expert on code efficiency :)

mausam

Posts: 243
Nickname: mausam
Registered: Sep, 2003

Re: help~!!! Posted: Sep 11, 2003 3:09 AM
Reply to this message Reply
Matt....any tutorial for that ;-)

Flat View: This topic has 17 replies on 2 pages [ « | 1  2 ]
Topic: HI what is wrong with this code??? Previous Topic   Next Topic Topic: Directory Encryption-file list problem and error

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use