编写一个应用程序,提示用户输入全名和街道地址,并根据用户的姓名首字母和地址的数字部分构造一个 ID。例如,住在 34 Elm 的用户 William Henry Harrison 的 ID 为 WHH34,而住在 1778 Monroe 的用户 Addison Mitchell 的 ID 为 AM1778。将文件另存为 ConstructID.java。
到目前为止,这是什么,我的老师说错了……
import java.util.*;
public class ConstructID {
public static void main(String[] args) {
String name1, address1, address2;
Scanner kevs = new Scanner(System.in);
System.out.println("Enter your fullname. Encluding Middle Initial, Separated by spaces.");
name1 = kevs.next();
name2 = kevs.next();
name3 = kevs.next();
name1 = name1.toUpperCase();
name2 = name2.toUpperCase();
name3 = name3.toUpperCase();
name1 = name1.substring(0,1);
name2 = name2.substring(0,1);
name3 = name3.substring(0,1);
System.out.println("\nEnter your address. Separated by spaces.");
address1 = kevs.next();
address2 = kevs.nextLine();
do {
if (address1 == address1.substring(0,1) || address1 == address1.substring(0,2) || address1 == address1.substring(0,3) || address1 == address1.substring(0,4) || address1 == address1.substring(0,5) || address1 == address1.substring(0,6))
System.out.println("\nYour ID: " + name1 + name2 + name3 + address1);
} while (address1 == address2);
}
}
注意:我不能使用数组:(这个问题的主题都是关于循环和字符串..没有数组..所以请帮助.. :((