代码拉取完成,页面将自动刷新
import java.util.Scanner;
public class PP11_2 {
public static void main(String[] args)throws StringTooLongException {
String A="",B;
String message="y";
Scanner scan = new Scanner(System.in);
StringTooLongException problem = new StringTooLongException("You put in too long!");
System.out.println("Please enter a word except 'DONE'.");
B = scan.nextLine();
A+=B;
while(message.equalsIgnoreCase("y")) {
while (B != "DONE") {
System.out.println("Please enter a word.");
System.out.println("Please enter 'DONE' if you want to quit.");
B = scan.nextLine();
A += B;
if (B.equals("DONE"))
break;
}
System.out.println(A + " Length: " + A.length());
try
{
if (A.length() > 20)
throw problem;
}
catch (StringTooLongException e)
{
System.out.println("You put in too long!");
}
finally {
System.out.println("DO you want to continue?");
message = scan.nextLine();
}
}
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。