Duvida sobre Thread.sleep?

1 resposta
P

Olá,

não consigui fazer dar esse resultado …

Given: 

 5. class Order2 implements Runnable {
 6.   public void run() { 
 7.     for(int x = 0; x < 4; x++) {
 8.       try { Thread.sleep(100); } catch (Exception e) { }
 9.       System.out.print("r");
10.   } }
11.   public static void main(String [] args) {
12.     Thread t = new Thread(new Order2());
13.     t.start();
14.     for(int x = 0; x < 4; x++) {
15.       // insert code here
16.       System.out.print("m");    
17. } } }

Which, inserted at line 15, is most likely to produce the output rmrmrmrm?

A Thread.sleep(1);
B Thread.sleep(100);
C Thread.sleep(1000);
D try { Thread.sleep(1); } catch (Exception e) { }
E try { Thread.sleep(100); } catch (Exception e) { }
F try { Thread.sleep(1000); } catch (Exception e) { }

1 Resposta

rdgms
class Order2 implements Runnable {  
	public void run() {   
		for(int x = 0; x < 4; x++) {  
			try { Thread.sleep(100); } catch (Exception e) { }  
			System.out.print("r");  
		} }  
	public static void main(String [] args) {  
		Thread t = new Thread(new Order2());  
		t.start();  
		for(int x = 0; x < 4; x++) {  
			try {
				Thread.sleep(100);
			} catch (InterruptedException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			 System.out.print("m");  
		} 
	} 
}

“most likely” as vezes funciona as vezes não … não da para controlar o exercicio esta pedindo a alternativa que pode se obter aquele resultado…
o 1 é muito rapido… o 1000 é muito lento… kkkk

Criado 15 de junho de 2009
Ultima resposta 15 de jun. de 2009
Respostas 1
Participantes 2