遇到个面试题,大家看看 面试题编码java基础 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 第一种好一些if(count++>10){ count++ 操作存在迷惑性不如第一种把count++ 单独提出去看着明白些 要是考虑第三种答案的话,可以试试回答两种都不太好,改造一下while的判定条件使其成为有限循环public class TestAB { public static void main(String[] args) throws Exception { try { (new TestAB()).a(); } catch (Exception e) { } try { (new TestAB()).b(); } catch (Exception e) { } try { (new TestAB()).c(); } catch (Exception e) { } } private void a() throws Exception { int count = 0; while (true) { count++; if (count > 10) { System.out.println(count); 抛异常(); } } } private void b() throws Exception { int count = 0; while (true) { if (count++ > 10) { System.out.println(count); 抛异常(); } } } private void c() throws Exception { int count = 0; while (count <= 10) { count++; if (count > 10) { System.out.println(count); 抛异常(); } } } private void 抛异常() throws Exception { throw new Exception(); }}输出:111211如果只让选a或者b的话,a相对好一些;b到12时才检出问题,抛异常,有逻辑错误 Java中的get和set方法究竟是什么意思? SSH jbpm 配置,请高手看看 将用户上传的图片转换成二维码并保存到数据库,急!! Io 异常: The Network Adapter could not establish the connection hibernate 写法请教 utf-8乱码,求助 hibernate MYSQL方言扩展!各位大侠请进! 调用axis服务出错的问题 求助struts中:form.java中使用数组的问题? 二维码生成及解析 ServerSocket中的accept问题。 免费送内部价值200元的50张北风网的学习卡
count++ 操作存在迷惑性
不如第一种把count++ 单独提出去看着明白些
public static void main(String[] args) throws Exception {
try {
(new TestAB()).a();
} catch (Exception e) {
}
try {
(new TestAB()).b();
} catch (Exception e) {
}
try {
(new TestAB()).c();
} catch (Exception e) {
}
} private void a() throws Exception {
int count = 0;
while (true) {
count++;
if (count > 10) {
System.out.println(count);
抛异常();
}
}
} private void b() throws Exception {
int count = 0;
while (true) {
if (count++ > 10) {
System.out.println(count);
抛异常();
}
}
} private void c() throws Exception {
int count = 0;
while (count <= 10) {
count++;
if (count > 10) {
System.out.println(count);
抛异常();
}
}
} private void 抛异常() throws Exception {
throw new Exception();
}
}
输出:
11
12
11如果只让选a或者b的话,a相对好一些;b到12时才检出问题,抛异常,有逻辑错误