Computer Science Canada NEED HELP PLZ! java integer - real program |
Author: | a_vatamanescu [ Wed Nov 03, 2004 8:18 pm ] |
Post subject: | NEED HELP PLZ! java integer - real program |
Hey eevryone. Im stuck at a program. The user inputs a number from which i have to make the program tell him/her if its either an integer or real. How would i do that? i tried doin this: if (answer < 0 && answer > 0) c.drawString ("Your number: " + answer + ".. is an integer", 250, 200); else c.drawString ("Your number: " + answer + ".. is real", 250, 200); BUT IT DOESNT WORK! if i input a decimal it gives me an error!. plz help me, i really need it! ![]() |
Author: | zylum [ Wed Nov 03, 2004 9:06 pm ] | ||
Post subject: | |||
wheres the part of the code where you get the input? once you get the input then you could do:
|
Author: | foobar247 [ Thu Nov 04, 2004 11:08 pm ] | ||||
Post subject: | |||||
you could try making use of the string parsing functions in Integer class so here you can test if some string can be parsed to int.
i'm not sure what was the desired effect of your code. as nothing would test true.
|