Hi,
I am trying to check whether a user inputs a number in a string with letters but every time i check this it only says there is a number if it is at the beginning of the string, otherwise it says there is no number and I was wondering if anyone could help. My code for this is below:
public void print()
{
if(number == false)
{
System.out.prin t("there is no number");
}
else if (number == true)
{
System.out.prin t("number");
}
}
boolean number = false;
public boolean number(String user)
{
for (int i=0; i<user.length() ;i++)
{
if ((user.charAt(i ))>=45 && (user.charAt(i) )<=57)
{
number = true;
return true;
}
else if(!((user.char At(i))>=45 && (user.charAt(i) )<=57))
{
i++;
//number = true;
//return true;
}
}
number=false;
return false;
}
I am trying to check whether a user inputs a number in a string with letters but every time i check this it only says there is a number if it is at the beginning of the string, otherwise it says there is no number and I was wondering if anyone could help. My code for this is below:
public void print()
{
if(number == false)
{
System.out.prin t("there is no number");
}
else if (number == true)
{
System.out.prin t("number");
}
}
boolean number = false;
public boolean number(String user)
{
for (int i=0; i<user.length() ;i++)
{
if ((user.charAt(i ))>=45 && (user.charAt(i) )<=57)
{
number = true;
return true;
}
else if(!((user.char At(i))>=45 && (user.charAt(i) )<=57))
{
i++;
//number = true;
//return true;
}
}
number=false;
return false;
}
Comment