日期:2014-05-17 浏览次数:20786 次
int tag = 1; if(tag==1){ for(int i=0; i<10000; i++){ System.out.print("测试A:"+i); } }else{ for(int i=0; i<10000; i++){ System.out.print("测试B:"+i); } }
int tag = 1; for(int i=0; i<10000; i++){ if(tag==1){ System.out.print("测试A:"+i); }else{ System.out.print("测试B:"+i); } }
int tag = 1; String method = tag == 1 ? "测试A" : "测试B"; for (int i = 0; i < 10000; i++) { //循环就尽量让它只是循环 System.out.println(method + i); }
------解决方案--------------------
public static void main(String[] args) { int tag = 1; java.util.Date begin=new java.util.Date(); if(tag==1){ for(int i=0; i<10000; i++){ System.out.print("测试A:"+i); } }else{ for(int i=0; i<10000; i++){ System.out.print("测试B:"+i); } } java.util.Date end=new java.util.Date(); System.out.println(); System.out.println(end.getTime()-begin.getTime()); java.util.Date begin1=new java.util.Date(); for(int i=0; i<10000; i++){ if(tag==1){ System.out.print("测试A:"+i); }else{ System.out.print("测试B:"+i); } } java.util.Date end1=new java.util.Date(); System.out.println(); System.out.println(end1.getTime()-begin1.getTime()); } }
------解决方案--------------------