那位大哥帮忙修改一下这段代码?
来源:百度知道 编辑:UC知道 时间:2024/05/18 20:21:36
import java.util.Scanner;
public class test1 {
private static final String INPUT_END = "END";
private static LinkedList<photoBean> photoInitList = new LinkedList<photoBean>();
private static boolean isphotoEnd = false;
private static int inputSize;
private static int photoCount = 1;
private static int current_sum;
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
String str = scanner.next();
try {
inputSize = Integer.parseInt(str);
}
catch (Exception e) {
System.out.print("error!");
return;
}
if (inputSize >= 800 && inputSize <= 2000) {
initphoto(scanner);
}
else {
System.out.println("error! enter a number between 800 and 2000!");
}
printphoto();
}
private
"A" 代表增加,“D" 代表删除,“END”代表输入结束。不知道你想干什么,只是改了下你的输入判断方法initphoto
private static void initphoto(Scanner scanner) {
while (!isphotoEnd) {
String command = scanner.next();
if (command.equalsIgnoreCase(INPUT_END)) {
isphotoEnd = true;
break;
}//增加的判断条件
String strFirst = scanner.next();
String strSecond = scanner.next();
String room = command + strFirst + strSecond;
String arrays[] = room.split(" ");
photoBean photo = new photoBean();
try {
photo.name = strFirst;
photo.anSize = Integer.parseInt(strSecond);
} catch (Exception e) {
System.out.println("input error!");
isphotoEnd = true;
break;
}
if (command.equalsIgnoreCase(INPUT_END)) {
isphotoEnd = true;
break;
}
else if (command.equals("A")) {
putphot