Home > Back-end >  Want to ask next for loop how to reduce the program running on time
Want to ask next for loop how to reduce the program running on time

Time:09-18

 
import java.util.Scanner;

Public class Source3 {

Public static void main (String [] args) {

Long startTime=System. CurrentTimeMillis ();

Long sum=0;


for(int i=1; i<=10000000; I++) {
The sum +=I;
}
long endTime=System.currentTimeMillis();
System.out.println(sum);
System. The out. Println (endTime - startTime);
}



}



Have what idea can reduce the program running time
  • Related