Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package training;
- import java.util.Scanner;
- public class Pendu {
- public static void main(String[] args) {
- int vie = 10;
- String mot1 = "petasse";
- String tableauresultat[] = new String[mot1.length()];
- String tableaumot[] = new String[mot1.length()];
- Scanner sc = new Scanner(System.in);
- for (int i = 0; i < mot1.length(); i++ ) {
- tableauresultat[i] = "*";
- tableaumot[i] = mot1.substring(i, i+1);
- }
- while (vie > 0) {
- System.out.println("Choissisez une lettre");
- String str = sc.nextLine();
- System.out.println("Vous avez saisi : " + str);
- String motactuel = "0";
- for (int i = 0; i < mot1.length(); i++ ) {
- if (str.equals(tableaumot[i])) {
- tableauresultat[i] = tableaumot[i];
- }
- motactuel = motactuel + tableauresultat[i];
- }
- motactuel = motactuel.replaceAll("[\\d]", "");
- vie = vie - 1;
- if (motactuel.equals(mot1)) {
- System.out.println("T'as gagné");
- System.out.println("le mot était bel et bien: " +mot1);
- break;
- }
- if (vie == 0) {
- System.out.println("tu as perdu");
- System.out.println("le mot était: " +mot1);
- System.out.println("try again");
- break;
- }
- System.out.println("Vous avez trouvé pour l'instant: "+ motactuel + " et il vous reste: " + vie + " vie(s) ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement