0
In the code below I have 4 for and they run in sequence, but I need them to run them all at the same time.
public class main
{
public static void main(String[] args)
{
long init = System.currentTimeMillis();
ataque(999999, 999999);
long end = System.currentTimeMillis();
long diff = end - init;
System.out.print("Demorou " + (diff / 1000) + " segundos");
}
public static void ataque(int limite, int busca)
{
int for1 = 0;
int for2 = limite / 4;
int for3 = for2 + for2;
int for4 = for2 = for3;
for(int i = for1; i < for2; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de " + busca + "\r");
}
for(int i = for2; i < for3; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de " + busca + "\r");
}
for(int i = for3; i < for4; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de " + busca + "\r");
}
for(int i = for4; i < limite; i++)
{
/*if(i == busca)
{
break;
}*/
System.out.println(i + " de " + busca + "\r");
}
}
}
You’ll have to use Threads, follow a link to give you a notion: link
– Rafael
Why do you need them at the same time? I think your problem is something else.
– Maniero
Does it have to be really at the same time? With exact accuracy? Or just finish and start at the same time? These details can make the difference when telling you how to solve your problem.
– Filipe Miranda
Good evening, I wonder if the answer helped you, if not please comment on what you think is missing.
– Guilherme Nascimento