-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLesson0007.java
44 lines (37 loc) · 1.53 KB
/
Lesson0007.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package JavaEducation;
import java.io.*;
public class Lesson0007 {
public static void main(String[] args)throws IOException {
String kelime = "money";int i,tahmin=0,anahtar=0,dogru=0;
String eldevar[] = new String[kelime.length()];
System.out.println("Kelimeyi bulmak için 4 yalniz hakkiniz var.");
BufferedReader klavye = new BufferedReader(new InputStreamReader(System.in));
for (i = 0; i < kelime.length(); i++)
{
eldevar[i] = "_ ";
}
finish:
while(tahmin<6){
System.out.println("Bir harf giriniz (Kalan hakkiniz "+(4 -tahmin) +") : ");
String harf = klavye.readLine();
tahmin++;
for (i = 0; i < kelime.length(); i++)
{
if (kelime.charAt(i) == harf.charAt(0))
{
eldevar[i] = harf+" ";
anahtar = 1;
dogru++;
if (dogru == kelime.length()) { System.out.println("kelime " +kelime+"...Tebrikler..."); break finish; }
}
}
if (anahtar == 1) { anahtar = 0; tahmin--; }
for (i = 0; i < kelime.length(); i++)
{
System.out.print(eldevar[i]);
}
System.out.println();
}
if (dogru != kelime.length()) { System.out.println("Uzgunum... Dogru yanit " + kelime); }
}
}