Hilos Basico En Java

  • Uploaded by: nestor
  • 0
  • 0
  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Hilos Basico En Java as PDF for free.

More details

  • Words: 147
  • Pages: 1
//Pequeño juego con dos hilos un ejemplo sencillo, solo guardenlo como .java y a compilar y ejecutar import java.io.*;  public class juego {  public static void main(String args[]) throws IOException {   H2 h2 = new H2();  h2.start();   } }  class H1 extends Thread {  public volatile boolean bandera = true;  int  num,numu;  public H1 ()  {  }  public void run() { num = ( int ) ( Math.random() * 11 ); BufferedReader br=new BufferedReader(new InputStreamReader(System.in));  try{   System.out.println(" Atinale del 1­10");  while(bandera) {  System.out.println("Dame un numero");  numu = Integer.parseInt(br.readLine());  if (num == numu) {  System.out.println("GANASTE");  bandera = false;  }else{System.out.println("Aun tienes tiempo");} 

}  }catch(IOException e){}

}  } class H2 extends Thread{ public H2(){} public void run(){ H1 h1=new H1(); h1.start(); for (int i=0;i<10;i++){  try { 

sleep( 1000 );  } catch ( InterruptedException e ) {}  if(h1.bandera == false) i=10; 

} }

} if(h1.bandera) System.out.println("Has perdido");  System.exit(0); h1.bandera = false;

Related Documents

Hilos Basico En Java
December 2019 35
Java Basico
May 2020 16
Hilos
April 2020 17
Apostila Java Basico 2
April 2020 14

More Documents from "Walter Jp"

Hilos Basico En Java
December 2019 35
October 2019 28
Derecho Colectivo.docx
April 2020 21
October 2019 29
October 2019 16