Compter en incrémentant la variable nbreCoups à chaque tour de boucle while.
package poubelle;
import java.util.Scanner;
public class Test {
public static void main(String[] args){
Scanner sc= new Scanner(System.in);
System.out.println(" taille maximale du chiffre ? ");
int limite= sc.nextInt();
int rand= (int)((Math.random())*limite)+1;
System.out.println("chiffre à trouvé " + rand);
int nbreCoups=1;
int rand2= (int)((Math.random())*limite)+1;
while (rand2!=rand){
rand2=(int)((Math.random())*limite)+1;
nbreCoups++;
System.out.println("Il faut trouvé le chiffre: " + rand + " et je propose " + rand2 + " pour la tentative n° " + nbreCoups);
}
}
}