2 Star 0 Fork 0

CS-IMIS-23/20172309_javaProgramming

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
PP11_2.java 1.23 KB
一键复制 编辑 原始数据 按行查看 历史
20172309 提交于 7年前 . 习题 11.2
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();
}
}
}
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/CS-IMIS-23/20172309_javaProgramming.git
git@gitee.com:CS-IMIS-23/20172309_javaProgramming.git
CS-IMIS-23
20172309_javaProgramming
20172309_javaProgramming
master

搜索帮助