Checking Name Legitimacy
Author |
Message |
Ninja
|
Posted: Fri Apr 07, 2006 10:09 am Post subject: Checking Name Legitimacy |
|
|
I am writing a program in my Java class. And using arrays and getchars, I am attempting to confirm the legitimacy of the characters through the use of ascii tables.
so essentially, it writes the characters into an array, then runs a huge if to ensure that the characters are within the bounds of Capital Letters and Lowercase. Symbols and numbers are to be ignored. I have this code done so far, but did it a bit back, and I thought you compare a string straight to its numeral ASCII counterpart
code: | while (Namecheck == 1) //For Loop for Future.
{
//c.println ("DEBUG2");
//[Compares each Character to the referenced numbers on Ascii table, eg. 65 - 90 = Capital Alphabet.Checks to ensure that characters entered for name are all letters, < Enter > , < Space > or < del >
while (AC <= 29)
{
if (Namearray [AC] >= 65 && Namearray [AC] <= 90 && Namearray [AC] >= 97 &&
Namearray [AC] <= 122 && Namearray [AC] == 127 && Namearray [AC] == 32 && Namearray [AC] == 14 && Namearray [AC] == 10) //]
{
Namecheck = 0; //sets namecheck to 0 to break th eloop
c.println ("Errornous name"); //prints errornous name, so I know that it is breaking
c.println (Namearray[5]); // loops that character, basically so I know it is touching this if
AC = 29; //sets the Arraycounter (AC) to 29 to break the first loop
}
else {
c.println (Namearray[1]); //loops this output to ensure it is hitting this else
//c.println ("Legit"+AC); //prints Legit then the Array position
}
AC++;
}
}
} |
Is essentially the code. I will document it here for easier readability. Basically, I am concerned that the if isn'tworking. how can I convert the char into an ascii number comparison. It was semi working before, from what I rememeber
I could do like char1 = 69; and when I used print (char1) it would print the symbol.
Any help for a newb =X |
|
|
|
|
|
Sponsor Sponsor
|
|
|
wtd
|
Posted: Fri Apr 07, 2006 11:57 am Post subject: (No subject) |
|
|
Please place comments on their own line, above the code they're referring to. It makes reading the code easier.
And use more consistent indentation.
Oh, and variable names should always begin with a lowercase letter. Only classes should be capitalized. Constants should be allcaps.
Now, as for the logic...
Why does setting "AC" to 29 break the outer loop? For that matter, what is AC?
If you want to break out of a loop, then you should express that intent directly using the break statement. If you need to break out of a loop other than the one you're in, you should learn to use labels in conjunction with loops.
code: | public class LoopTest {
public static void main(String[] args) {
int[] foo = {23, 45, 21, 98, 43, 37};
outer_loop:
for (int i = 0; i < foo.length; i++) {
System.out.println("" + Integer.toString(i) + ":");
for (int j = 0; j < foo.length; j++) {
System.out.println(" " + Integer.toString(foo[j]));
if ((i + foo[j] + 1) % 5 == 0) {
break outer_loop;
}
}
}
}
} |
This will print:
code: | 0:
23
45
21
98
43
37
1:
23 |
|
|
|
|
|
|
wtd
|
Posted: Fri Apr 07, 2006 11:58 am Post subject: (No subject) |
|
|
As for your ASCII question... ASCII characters are integers. |
|
|
|
|
|
|
|