60 lines
		
	
	
		
			1006 B
		
	
	
	
		
			Java
		
	
	
	
	
	
		
		
			
		
	
	
			60 lines
		
	
	
		
			1006 B
		
	
	
	
		
			Java
		
	
	
	
	
	
|   | /**
 | |||
|  |  * 
 | |||
|  |  */
 | |||
|  | package fr.blankoworld.compteur;
 | |||
|  | 
 | |||
|  | /**
 | |||
|  |  * @author 3dossmanno
 | |||
|  |  *
 | |||
|  |  */
 | |||
|  | public class Compteur extends Thread{
 | |||
|  | 
 | |||
|  | 	private String nom;
 | |||
|  | 	private int max;
 | |||
|  | 	private int ordreArrivee;
 | |||
|  | 	/**
 | |||
|  | 	 * @param args
 | |||
|  | 	 */
 | |||
|  | 	
 | |||
|  | 	public static void main(String[] args) {
 | |||
|  | 		// TODO Auto-generated method stub
 | |||
|  | 		
 | |||
|  | 			Compteur cpt;
 | |||
|  | 			
 | |||
|  | 			if(args.length%2 == 0) {
 | |||
|  | 					
 | |||
|  | 				for(int i = 0; i < args.length; i+=2)
 | |||
|  | 				{
 | |||
|  | 						cpt = new Compteur(args[i], Integer.parseInt(args[i+1]));
 | |||
|  | 						cpt.start();
 | |||
|  | 						
 | |||
|  | 				}
 | |||
|  | 			}
 | |||
|  | 			else
 | |||
|  | 			{
 | |||
|  | 				System.out.println("Syntaxe: [Nom MAX]+");
 | |||
|  | 			}
 | |||
|  | 			
 | |||
|  | 	}
 | |||
|  | 	
 | |||
|  | 	public Compteur(String name, int mx)
 | |||
|  | 	{
 | |||
|  | 		this.nom = name;
 | |||
|  | 		this.max = mx;
 | |||
|  | 		this.ordreArrivee = 0;
 | |||
|  | 	}
 | |||
|  | 	
 | |||
|  | 	public void run()
 | |||
|  | 	{
 | |||
|  | 		for(int j = 1; j <= this.max; j++){
 | |||
|  | 			this.ordreArrivee ++;
 | |||
|  | 			try {
 | |||
|  | 				sleep( (int)(Math.random()*5000) );
 | |||
|  | 			} catch ( InterruptedException ex ) {
 | |||
|  | 			}
 | |||
|  | 			System.out.println(this.nom + ": " + this.ordreArrivee);
 | |||
|  | 		}
 | |||
|  | 		
 | |||
|  | 		System.out.println(this.nom + " a fini de compter jusqu'<27> " + this.max);
 | |||
|  | 	}	
 | |||
|  | }
 |