Add for loops and display time for both System.out.pritnln and System.out.printf. The code is not displying the time it takes for both System.out.pritnln and System.out.printf. Any help will be greatly appreciated. This is in Java. The code I wrote is as follows: public class optMain { /** * @param args the command line arguments */ public static void main(String[] args) { // TODO Auto-generated method stub long start, stop=0; long elpasedTime=0; start = System.nanoTime(); for (int i=0;i<100;i++) { System.out.println(" The number is "+i); } stop = System.nanoTime() - start; elpasedTime=stop-start; //calculate time in seconds for the println in for loop double printlntime=(double)elpasedTime / 1000000000.0; start = System.nanoTime(); for (int i=0;i<100;i++) { System.out.printf(" The number is %d\n",i); } stop = System.nanoTime() - start; elpasedTime=stop-start; double printfTime=(double)elpasedTime / 1000000000.0; //calculate time in seconds for the printf in for loop System.out.println("It took "+printlntime+" seconds for code to run println "); System.out.printf("It took "+printfTime+" seconds for code to run printf"); } }
Please Send me answer within 10 min!! I will rate you good for sure!!
Add for loops and display time for both System.out.pritnln and System.out.printf. The code is not displying the time it takes for both System.out.pritnln and System.out.printf. Any help will be greatly appreciated. This is in Java. The code I wrote is as follows:
public class optMain {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long start, stop=0;
long elpasedTime=0;
start = System.nanoTime();
for (int i=0;i<100;i++)
{
System.out.println(" The number is "+i);
}
stop = System.nanoTime() - start;
elpasedTime=stop-start;
//calculate time in seconds for the println in for loop
double printlntime=(double)elpasedTime / 1000000000.0;
start = System.nanoTime();
for (int i=0;i<100;i++)
{
System.out.printf(" The number is %d\n",i);
}
stop = System.nanoTime() - start;
elpasedTime=stop-start;
double printfTime=(double)elpasedTime / 1000000000.0;
//calculate time in seconds for the printf in for loop
System.out.println("It took "+printlntime+" seconds for code to run println ");
System.out.printf("It took "+printfTime+" seconds for code to run printf");
}
}
![Add for loops and display time for both System.out.pritnln and System.out.printf. The code is not displying the time it
takes for both System.out.pritnln and System.out.printf. Any help will be greatly appreciated. This is in Java. The code I
wrote is as follows:
public class optMain {
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
long start, stop=0;
long elpased Time=0;
start = System.nanoTime();
for (int i=0;i<100;i++)
{
System.out.println(" The number is "+i);
}
stop = System.nanoTime() - start;
elpasedTime-stop-start;
//calculate time in seconds for the printin in for loop
double printlntime=(double)elpasedTime / 1000000000.0;
start = System.nanoTime();
for (int i=0;i<100;i++)
{
System.out.printf(" The number is %d\n",i);
}
stop = System.nanoTime() - start;
elpasedTime-stop-start;
double printfTime=(double)elpased Time / 1000000000.0;
//calculate time in seconds for the printf in for loop
System.out.println("It took "+printlntime+" seconds for code to run println ");
System.out.printf("It took "+printfTime+" seconds for code to run printf");](/v2/_next/image?url=https%3A%2F%2Fcontent.bartleby.com%2Fqna-images%2Fquestion%2Fa1281e27-cece-46b8-b84c-7eab1e49b972%2F66fc3a53-025f-4b4b-8adf-a981aace0bdb%2Fvmh759f_processed.jpeg&w=3840&q=75)

Step by step
Solved in 4 steps with 7 images









