i need to make sure a string is in the correct format like so "123-A"
i've tried several different ways and i'm getting frustrated
here's one of my test codes for this problem
public class TestCharacter
{
public static void main(String[] args)
{
String str = "123-a";
int length;
boolean isTrue = true;
length = str.length();
for (int i = 0; i < 3; i++)
{
if (Character.isLetter(str))
{
isTrue = false;
}
}
if (str.charAt(3) != "-")
{
isTrue = false;
}
if (!str.charAt(4).isLetter)
{
isTrue = false;
}
if (isTrue = true)
{
System.out.println("The string is valid");
}
str = "12345";
for (int i = 0; i < 3; i++)
{
if (Character.isLetter(str))
{
isTrue = false;
}
}
if (str.charAt(3) != "-")
{
isTrue = false;
}
if (!str.charAt(4).isLetter)
{
isTrue = false;
}
if (isTrue = true)
{
System.out.println("The string is valid");
}
}
}
What the hey am I doing wrong?

New Topic/Question
Reply



MultiQuote




|