Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Testing for an integer in java

Name: Anonymous 2007-04-19 19:54 ID:OeZSnxtN

I was just wondering if there was a simple and easy way to test if a string(single char string) is a number.

Maybe some method I do not know about, or maybe something like

if (string[1].equals(\\#))

Any thoughts?

Name: Anonymous 2007-04-19 20:11 ID:gARKv9H1

Integer.parseInt(String value);

Name: Anonymous 2007-04-19 20:31 ID:OeZSnxtN

But I don't want to parse the string. I just want to test it to see if it is an integer or not.

I could probably use exception handling to see if it will parse or not, but I was just wondering if there is an easier way.

Name: Anonymous 2007-04-19 20:35 ID:gARKv9H1

>>3

In that case, just run a loop from the beginning to the end of the string, checking to see if each character is between '0' and '9' inclusive. If any don't match or the string is of zero length, it's not an integer. Otherwise it is.

Name: Anonymous 2007-04-19 20:39 ID:Heaven

I FEEL NOTHING FOR YOU. I HOLD MYSELF DOWN. KEEP TO YOURSELF. YOU SHOULDN'T TOUCH ME. THE SKIN PEELS OFF MY BONES. I'LL GIVE YOU A GIFT, TAKE THE SKIN FROM MY STOMACH AND STRETCH IT ACROSS YOUR FACE. LOOK IN THE MIRROR, I SEE MYSELF THROUGH YOUR EYES. MY BODY'S ON THE GROUND BEHIND YOU. YOU USE IT TO AMUSE YOURSELF. WHEN YOU KICK IT AROUND THE ROOM YOU FEEL THE IMPACT OF MY BOOT IN YOUR STOMACH. CRY FOR ME, BLAME ME FOR THE FACT YOU NO LONGER RECOGNIZE YOURSELF. LYING HERE, I WANT THE AIR IN THIS ROOM TO CONSUME ME, TO TO PULL MY BODY IN BEHIND ITSELF WHILE YOU STARE DOWN AT ME, UNCERTAIN IF YOU'VE LOST YOURSELF IN ME. YOU'RE RUNNING YOUR HANDS ALONG THE LEATHER SURFACE OF YOUR SKIN. THE SOUND THIS MAKES CHANGES PITCH ACCORDING TO THE AREA OF YOUR BODY YOU TOUCH, YOUR THIGHS AND YOUR GROIN RELEASE A LOW HUM, THE SOUND OF MY CORPSE RELEASING DEAD AIR WHEN YOU KICK ME. YOUR FACE GENERATES A CONTINUOUS HIGH-PITCHED SQUEAL, THE SOUND I MAKE WHEN YOU BURN ME. I TAKE YOU OVER, YOU FORGET YOURSELF IN MY BODY, WHEN YOU CHEW A PIECE OF SKIN FROM YOUR FINGER YOU REMEMBER MY BODY IN YOUR MOUTH. MY BONES CRACK BETWEEN YOUR TEETH. I LOVE YOU. WHEN YOU LICK YOUR HAND YOUR SWEAT TASTES LIKE MY BLOOD. CONCEAL YOURSELF. CLOSE YOURSELF OFF. PULL BACK INTO MY SKIN. I'M INSIDE YOU. THE PLACE ON THE FLOOR WHERE MY BODY DECAYED LEFT A STAIN ON YOUR MEMORY. THAT'S A SIGNATURE OF MY LOVE FOR YOU. YOU CAN'T FORGET ME WITHOUT LOSING YOURSELF. I'LL NEVER DIE.

Name: Anonymous 2007-04-20 6:55 ID:V9osOUg+

>>1
Check the docs on java.util.regex (the only useful part of the Java library, and still comes with a retarded interface), and use Perl-compatible regular expressions to check for:
/^\s*-?\d+\s*$/

For floating point numbers:
/^\s*-?(?:\.\d+|\d+)\s*$/

Name: Anonymous 2007-04-20 6:57 ID:V9osOUg+

>>6
Aww shit, premature postaculation.

For floating point numbers:
/^\s*-?(?:\.\d+|\d+(?:\.\d*)?)(?:[Ee][+-]?\d+)\s*$/

Name: Anonymous 2007-04-20 6:58 ID:V9osOUg+

>>7
Oops, forced exponentiation of floating point numbers, thread over.

For floating point numbers, fixed:
/^\s*-?(?:\.\d+|\d+(?:\.\d*)?)(?:[Ee][+-]?\d+)?\s*$/

Name: Anonymous 2007-04-20 6:59 ID:Heaven

>>1
LOOOOOL jaaaavaaaaaaaaaaaa hahahhaaha

Name: Anonymous 2007-04-20 7:08 ID:mZDLYWuu

public class IsStringAnInteger {

    private static IsStringAnInteger instance;

    public IsStringAnInteger getInstance() {
        if (instance == null) {
            instance = new IsStringAnInteger();
        }
        return instance;
    }[code]public class IsStringANumber {

    private static IsStringANumber instance;

    public IsStringANumber getInstance() {
        if (in

    public bool isStringAnInteger(String isThisStringAnInteger) {
        boolean stringIsAnInteger = false;
        int min = getMinimumInteger();
        int max = getMaximumInteger();
        for (int val = min; val <= max; val++) {
            Integer integer = new Integer(val);
            String stringWhichIsAnInteger = integer.toString();
            if (isThisStringAnInteger.equals(stringWhichIsAnInteger)) {
                stringIsAnInteger = true;
            }
        }
        return stringIsAnInteger;
    }

    private int getMinimumInteger() {
        return Integer.MIN_VALUE;
    }

    private int getMaximumInteger() {
        return Integer.MAX_VALUE;
    }

}


I KNOW BECAUSE I AM AN EXPERT JAVA PROGRAMMER

Name: Anonymous 2007-04-20 7:15 ID:l6Bved/C

C:

main() {
char c = '9';
if(isdigit(c)) printf("%c is a number! \n", c);
}


Or even:

#define isnum(x) \
((x >= '0') && (x <= '9'))

Name: Anonymous 2007-04-20 7:23 ID:VIteSzSV

>>11
fuck you off topic moron

Name: Anonymous 2007-04-20 9:18 ID:/t9vQDIX

>>10

Hahaha, very good

Name: Anonymous 2007-04-20 14:20 ID:Heaven

>>10
You forgot the singleton and factory

Name: Anonymous 2010-12-17 1:31

Are you GAY?
Are you a NIGGER?
Are you a GAY NIGGER?

If you answered "Yes" to all of the above questions, then GNAA (GAY NIGGER ASSOCIATION OF AMERICA) might be exactly what you've been looking for!

Name: Sgt.Kabu➹kimanቘ㹊 2012-05-29 0:45

Bringing /prog/ back to its people
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy
All work and no play makes Jack a dull boy

Don't change these.
Name: Email:
Entire Thread Thread List