【发布时间】:2018-04-03 01:11:16
【问题描述】:
我现在正在处理一项任务,我必须以“ABC123456”格式输入一个输入,看看它是否有效。我不明白如何检查每个字符是数字还是字母。这是我到目前为止所拥有的:
import java.util.Scanner;
public class NetID {
public static void main(String[] args) {
Scanner input = new Scanner (System.in);
String userInput, char0thru2, char3thru8, uppercase, netID;
System.out.println("Please enter the NetID to verify:");
userInput = input.nextLine();
if (userInput.length() != 9) {
System.out.println("Your NetID needs to be 9 characters long, it needs to be in this format: ABC123456");
}
if (userInput.length() == 9){
char0thru2 = userInput.substring(0, 3);
char3thru8 = userInput.substring(3, 9);
uppercase = char0thru2.toUpperCase();
}
}
}
【问题讨论】: