0% found this document useful (0 votes)
914 views

Hangman Source Code With Java

I made this source by Java that can be used in any platform , this source could be redistributed for anyone else, don't forget to leave footprint before you download this source :) Have a nice day and Happy Programming

Uploaded by

Yosep Wijaya
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
914 views

Hangman Source Code With Java

I made this source by Java that can be used in any platform , this source could be redistributed for anyone else, don't forget to leave footprint before you download this source :) Have a nice day and Happy Programming

Uploaded by

Yosep Wijaya
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

import java.util.

Scanner;

public class tolo1 {

public static String bebas()

String mama = "";

switch((int)(Math.random()*10))

case 0 :

mama = "sekolah";

break;

case 1 :

mama = "kalimantan";

break;

case 2 :

mama = "lulu";

break;

case 3 :

mama = "suram";

break;

case 4 :

mama = "buku";

break;

case 5 :

mama = "God";

1
break;

case 6 :

mama = "hantu";

break;

case 7 :

mama = "holo";

break;

case 8 :

mama = "haha";

break;

case 9 :

mama = "dodo";

break;

case 10 :

mama = "java";

break;

return mama;

public static void cetaknyawa(int life)

for(int i=1;i<=life;i++)

System.out.print("X");

2
}

public static String cetakbintang(String a)

String terserah = "";

for(int i=1;i<=a.length();i++)

if(a.charAt(i-1) == ' ' )

terserah += " ";

else

terserah += "*";

return terserah;

public static void tolo()

int life = 5;

int poin = 20;

System.out.print(" HP = ");cetaknyawa(life);

3
System.out.println(" Poin = " + " " + poin);

System.out.println(" ");

String theWord = bebas();

String theLetters = "";

String soFar = cetakbintang(theWord);

while (soFar.indexOf("*") != -1){

Scanner scanner = new Scanner(System.in);

System.out.println("Current Pharase is: " + soFar);

System.out.println("Letter so far: " + theLetters);

System.out.println("Your next guess: ");

String letter = scanner.next();

theLetters+= letter;

String newWord = "";

boolean cek = false;

for (int i=0; i < theWord.length();i++)

if (theWord.charAt(i) == letter.toLowerCase().charAt(0))

4
newWord += letter;

else

cek = true;

newWord += soFar.charAt(i);

if(cek) {

life--;

cetaknyawa(life);

if(life == 0)

System.out.println("Anda kalah, kesempatan


habis");

poin -= 10;

System.out.println(poin);

System.exit(0);

soFar = newWord;

5
}

System.out.println("\nCongratolation!, The word is '" + theWord


+ "'");

public static void main(String[] args) {

tolo();

You might also like