[Java] 纯文本查看 复制代码
public class Test16 {
public static void main(String[] args) throws ParseException {
SimpleDateFormat sb = new SimpleDateFormat("yyyy年MM月dd日");
Date now = sb.parse("2018年02月01日");
long l = now.getTime();
// 这里在进行运算时出现了错误
long lo = 100*24*60*60*1000L + l;
Date d = new Date(lo);
String str = sb.format(d);
System.out.println("100天后的时间为:" + str);
}
}
[Java] 纯文本查看 复制代码
public class Test06 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
ArrayList<Double> list = new ArrayList<>();
for (int i = 0; i < 8; i++) {
System.out.println("请录入第" + (i + 1) + "个评委成绩:");
double score = sc.nextDouble();
list.add(score);
}
double max = list.get(0);
double min = list.get(0);
double sum = 0;
for (Double aDouble : list) {
sum += aDouble;
if (max < aDouble) {
max = aDouble;
}
if (min > aDouble) {
min = aDouble;
}
}
// 问题出现在这里,在最终输出语句中,由于表达式中的数字均为int数字,所以导致最后平均分出现整数。
System.out.println("选手的最终得分为:" + ((sum - max - min) / (list.size() - 2)));
}
}
[Java] 纯文本查看 复制代码
public class Test04 {
public static void main(String[] args) {
Collection<String> coll = new ArrayList<String>();
coll.add("123");
coll.add("1234");
coll.add("12345");
coll.add("654123");
coll.add("456789123");
coll.add("1112222333444");
coll.add("555555");
Collection<String> coll1 = new ArrayList<>();
// 这里是最开始出现异常的地方。在增强for循环当中使用了remove方法。
for (String s : coll) {
if (s.length() >= 5 && s.length()<= 10) {
coll1.add(s);
}
}
for (String s : coll1) {
System.out.println(s);
}
}
}