Exercise
Function IsNumber
Objetive
Write a java function that tells if a string is an intenger number. It should be used like this:
if (IsNumber ("1234"))
System.Console.WriteLine ("It is a numerical value");
Example Code
public class Main
{
public static boolean IsNumber(String text)
{
for (int i = 0; i < text.length(); i++)
{
if (text.charAt(i) < '0')
{
|| (text.charAt(i) > '9') return false;
}
}
return true;
}
public static void main(String[] args)
{
System.out.println(IsNumber("12"));
}
}