functions?
what if I wanna test if an integer is really an integer what will i do?
if in PHP ther is a ceratain **** as is_string or is_boolean or is_int
well how bout in JAVA then?
what if I wanna test if an integer is really an integer what will i do?
if in PHP ther is a ceratain **** as is_string or is_boolean or is_int
well how bout in JAVA then?
> well how bout in JAVA then?
Integer.parseInt() is one way. Regular expressions are another. Character.isDigit() is another. That's just a start.
~
Write an application that reads five integers, determines and prints the largest and smallest integers in the group. Use only the programming techniques you learned in this chapter.
> Write an application that reads five integers,
> determines and prints the largest and smallest
> integers in the group. Use only the programming
> techniques you learned in this chapter.
You probably didn't mean for that to sound like you want someone to do your homework. So, what's your specific, code-related question?
~
since I know a lil in PHP
my specific question is how am I going to test
the input integer if it was realy an integer ? or else if its not ..output
in PHP the code can be like this
if (is_int(num1))
{
echo "the 1st input is an integer";
}
else
{
echo "it is not an integer";
}
how bout in java how will you apply such logic in comparing? such like that
i just shown
> my specific question is how am I going to test the input integer if it was realy an integer ?
See reply #1. Which part of reply #1 did you find confusing?
~
sorry friend, its back to the ranch with you
http://java.sun.com/docs/books/tutorial/java/index.html
Integer.parseInt() Character.isDigit()
these two things.. I have encounter those two in using JOption pane
but I'm using the java.util.Scanner instead Integer.parseInt(JOptionPane.showInputDialog("enter number: "));
ouch..my nose is bleeding ! :(
> Integer.parseInt() Character.isDigit()
>
>
> these two things.. I have encounter those two in
> using JOption pane
So? They have nothing to do with JOptionPane See the Integer in front of the parseInt and the Character in front of the isDigit. That means they are static methods of the corresponding classes. They are totally independent of JOptionPane and you can use them anywhere you like in your code.
Try a bit of lateral thinking.
Did you look at the documentation of the Scanner class?
int number;
If( Scanner.hasNextInt() ) number=Sxanner.nextInt();
else System.out.println("not an Integer");
Just have to insert "try" and "catch" because Scanner.nextInt throws an Exception.