Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please use Java and follow the instruction to finish this question. Thanks a lot

ID: 3889526 • Letter: P

Question

Please use Java and follow the instruction to finish this question. Thanks a lot,

This assignment asks you to implement a number of methods for a class Complexity. These methods should be implemented using for loops, as seen in class (except for the extra-credit one). In addition, each of these methods should print out the value of an accumulator that counts the number of "operations" performed. The notion of "operation" should be taken loosely; the idea is that if you are requested to implement a method of time complexity O(n), then it should print out values from 1 to n (or close enough). For example, the following void public method0 (int n) ( int counter=0; for (i-0; i

Explanation / Answer

public class Complexity {

public void printMethod1(int n)

{

int count=0;

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

System.out.println("Operation + counter"+count);

count++;

}

}

}

public void printMethod4(int n)

{

int count=0;

for(int i=0;i<n;i++)

{

for(int j=0;j<n;j++)

{

for(int k=0;k<n;k++)

{

System.out.println("Operation + counter"+count);

count++;

}

}

}

}

public static void main(String[] args) {

// TODO Auto-generated method stub

Complexity obj=new Complexity();

obj.printMethod1(10);

obj.printMethod4(40);

}

}