java常见错误
。。。!!
这个作者很懒,什么都没留下…
展开
-
java中的一些异常
public class TestException { public static void main(String[] args) { int a = 10; System.out.println(a/0); }}Exception in thread "main" java.lang.ArithmeticException: / by zero当运行时,被除数为0的时候会显示异常。...原创 2021-10-21 09:09:51 · 74 阅读 · 1 评论 -
java8中LocalDate.parse参数中出现的坑
//错误var today = LocalDate.parse("2021-1-1");//System.out.println("today = "+ today);//正确today = LocalDate.parse("2021-01-01");System.out.println("today = "+ today);这个参数中的月和日都必须是两位数,如果是一位数的话就如上面的代码一样,往前面添加个0。...原创 2021-10-20 15:42:48 · 3786 阅读 · 1 评论 -
数组索引出界异常
public class TestError { public static void main(String[] args) { int b[] = new int[2]; System.out.println(b[3]); }}报错:java.lang.ArrayIndexOutOfBoundsException原创 2021-09-22 21:12:17 · 175 阅读 · 1 评论 -
字符串索引出界异常
public class TestError { public static void main(String[] args) { String a = "123456"; System.out.println(a.charAt(7)); }}出界异常:java.lang.StringIndexOutOfBoundsException原创 2021-09-22 21:08:37 · 148 阅读 · 0 评论