Let me try to help you learn to debug problems. The following is the same as the code you posted in
post #4, but with additional println statements added to show what happens when you execute the program.
import java.util.*;
class lab5 {
public static void main(String[] args) {
String[] type = { "byte", "short", "int", "long", "float", "double", "Boolean", "char",
"String" };
System.out.println("Enter a Java declaration followed by ; ");
Scanner s = new Scanner(System.in);
boolean validtype = false;
while (true) {
String input = s.nextLine();
String[] result = input.split(" ");
System.out.println(">>> A) result = " + Arrays.deepToString(result));
System.out.println(">>> B) result[0] = " + result[0]);
for (int i = 0; i < type.length; i++) {
System.out.println(">>> C) type[" + i + "] = " + type[i]);
if (type[i].equals(result[0])) {
validtype = true;
System.out.println("Type is " + type[i]);
if (result[1].substring(result[1].length() - 1).equals(";")) {
result[1] = result[1].substring(0, result[1].length() - 1);
System.out.println("Varible is " + result[1]);
}
else {
System.out.println("Please enter again with ;");
}
} // end of first if statement
System.out.println(">>> D) validtype = " + validtype);
validtype = true;
} // end of else for loop
System.out.println(">>> E) validtype = " + validtype);
if (!validtype) {
System.out.println("Unknown Type " + result[1]);
} // end of if statement^
break;
} // end of while loop
} // end of main method
} // end of class
Compile and run the above, and observe the ">>>" print outs. Try to figure out the reason it doesn't print "Unknown Type" when it is supposed to do so. Add additional println statements as necessary. Also, from the ">>>" print outs think how your code might be better structured to get the necessary results.