【发布时间】:2015-03-06 00:28:50
【问题描述】:
我正在尝试构建一个程序
- 找到
@符号,然后 - 找到教育电子邮件地址的
.edu部分,最后 - 删除
@school.edu部分,并返回其余部分。
我已尝试使用charAt,但我不断收到不兼容类型错误,并且我不确定如何删除每次可能位于不同位置的字符串部分。欢迎任何指导。
这是我目前所拥有的:
if (UserEmail.charAt(0) == (".edu"))
String UserName = UserEmail.substring(0,//location of @//)
else
System.out.print(UserEmail + "is not an acceptable email address.
System.out.print("Type your email address.");
UserEmail = kb.nextLine();
【问题讨论】:
-
我认为您的代码块中缺少括号和引号。
-
我改进了格式和语法。
-
谢谢@Benjamin 和@Jubobs!