Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package alg717254455R.s2;
- import java.util.Random;
- public class Loop4 {
- public static void loop4(int n) {
- /*Quadratic algorithm O(n^4) */
- 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<=i; k++)
- for (int l=1; l<=i; 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++){
- loop4(n);
- }
- t2 = System.currentTimeMillis();
- System.out.println ("n="+n+ "**TIME=" +(t2-t1)+ " ** nTimes=" + nTimes);
- } //for
- } //main
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement