1
After the execution of the 4 functions it should print the time it took to execute
public class main
{
public static void main(String[] args)
{
long init = System.currentTimeMillis();
ataque1();
ataque2();
ataque3();
ataque4();
long end = System.currentTimeMillis();
long diff = end - init;
System.out.print("Demorou " + (diff / 1000) + " segundos");
}
static int for1 = 0;
static int for2 = 20 / 4;
static int for3 = for2 + for2;
static int for4 = for2 = for3;
public static void ataque1()
{
new Thread()
{
@Override
public void run()
{
int for11 = for1;
int for22 = for2;
int for33 = for3;
int for44 = for4;
for(int i = for1 ; i <= for2; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de 999999");
}
}
}.start();
}
public static void ataque2()
{
new Thread()
{
@Override
public void run()
{
int for11 = for1;
int for22 = for2;
int for33 = for3;
int for44 = for4;
for(int i = for2; i <= for3; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de 999999");
}
}
}.start();
}
public static void ataque3()
{
new Thread()
{
@Override
public void run()
{
int for11 = for1;
int for22 = for2;
int for33 = for3;
int for44 = for4;
for(int i = for3; i <= for4; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de 999999");
}
}
}.start();
}
public static void ataque4()
{
new Thread()
{
@Override
public void run()
{
int for11 = for1;
int for22 = for2;
int for33 = for3;
int for44 = for4;
for(int i = for4; i <= 20; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de 999999");
}
}
}.start();
}
But the time that took in the middle of the execution appears instead of the end
0 de 999999
1 de 999999
2 de 999999
3 de 999999
4 de 999999
5 de 999999
6 de 999999
7 de 999999
8 de 999999
9 de 999999
Demorou 0 segundos10 de 999999
11 de 999999
12 de 999999
13 de 999999
14 de 999999
15 de 999999
16 de 999999
17 de 999999
18 de 999999
19 de 999999
20 de 999999
What this line is doing?
static int for4 = for2 = for3;
You want the value offor4
be equal tofor2
and equal tofor3
, which in turn is10
?– mgibsonbr