請問多重循環和單循環+if break哪種更好?
我用for 循環搭配if break也完成了,想請比較一下這樣寫和標答的多重循環寫法的優劣。謝謝!
public?class?HelloWorld{ ????public?static?void?main(String[]?args){ ????????int?num?=?999; ????????for(int?count?=?0;count<10;count++){ ????????????if(num<?(Math.pow(10,count))){ ????????????????System.out.println("它是個"+count+"位的數!");???? ????????????????break; }}}}
2018-11-03
調用了類庫函數,降低了效率;而且層次結構易讀性差了一點點。