Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package labs.course15_16.lab1_2;
- import java.util.Random;
- public class Loop4 {
- public static void loop3(int n) {
- /*Quadratic algorithm O(n^2) */
- Random rn = new Random();
- @SuppressWarnings("unused")
- int cont=0;
- for (int i=1; i<=n; i++)
- for (int j=1; j<=i; j++)
- for (int k=1; k<=j; k++)
- for (int l=1; l<=k; l++)
- cont += rn.nextInt();
- }
- public static void main(String arg []){
- long t1,t2;
- int nTimes= Integer.parseInt(arg [0]);
- for (int n=1; n<=100000; n*=2) {
- t1 = System.currentTimeMillis();
- for (int repetitions=1; repetitions<=nTimes; repetitions++) {
- loop3(n);
- }
- t2 = System.currentTimeMillis();
- System.out.println ("n="+n+ "**TIME="+(t2-t1)+" **nTimes="+nTimes);
- } // for
- } // main
- } //class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement