我有一个应该具有特征的汽车对象。该特征应该有要求:以两个大写字母开头,后跟1-9的数字,然后是0-9的4个数字。
公共无效writeCharacteristic(){
System.out.println("write down the characteristic for the car.");
String characteristic = kb.nextLine();
progress = false;
if (characteristic.length() != 7){
System.out.println("The string is not 7 letter/numbers long");
progress = false;
}
for(int i = 0; i < 2; ++i){
if (characteristic.charAt(i) < "A" || characteristic.charAt(i) > "Z"){
System.out.println(" character number " + i + " is invalid");
progress = false;
}
}
if (characteristic.charAt(3) < "1" || characteristic.charAt(3) > "9")
progress = false;
for (int j = 3; j < 7; ++j){
if (characteristic.charAt(j) < 0 || characteristic.charAt(j) > 9)
progress =false;
}
if (progress == false){
System.out.println("characteristic will have the value null.");
characteristic = null;
}
if (progress == true)
car.setCharacteristic(characteristic);
}
我在“if (characteristic.charAt(i) < "A" || characteristic.charAt(i) > "Z"){" 行有问题
编译器说“操作符 < 未定义参数类型 char、String”
非常感谢任何帮助,谢谢。