avatar
问个外循环和内问题# JobHunting - 待字闺中
S*1
1
为啥外层循环小内层循环大的结构快呢?
public static void main(String[] args){
long z;
Date a=new Date();
for(long i=0; i<10;i++)
for(long j=0;j<1000000000;j++)
z=i*j;
Date b=new Date();
System.out.println(b.getTime()-a.getTime());

}
public static void main(String[] args){
long z;
Date a=new Date();
for(long i=0; i<1000000000;i++)
for(long j=0;j<10;j++)
z=i*j;
Date b=new Date();
System.out.println(b.getTime()-a.getTime());
}
avatar
x*n
2
because in the inner loop, you have a temporary variable j, it will be "
newed" and "deleted" by 10 times at the first situation, while it will do
the same by 10000000 times at the second situation.
avatar
S*1
3
明白了,谢谢你!

【在 x*********n 的大作中提到】
: because in the inner loop, you have a temporary variable j, it will be "
: newed" and "deleted" by 10 times at the first situation, while it will do
: the same by 10000000 times at the second situation.

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。