-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsayiTahmin.java
More file actions
58 lines (48 loc) · 1.83 KB
/
sayiTahmin.java
File metadata and controls
58 lines (48 loc) · 1.83 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import java.util.Random;
import java.util.Scanner;
public class sayiTahmin {
public static void main(String[] args) {
Random rand = new Random();
int num = rand.nextInt(100);
Scanner inp = new Scanner(System.in);
int right = 0;
int selected;
boolean isWin = false;
boolean isMistake = false;
System.out.println(num);
while (right < 5) {
System.out.print("Lutfen tahmininizi giriniz : ");
selected = inp.nextInt();
if (selected < 0 || selected > 99) {
System.out.println("Lutfen 0-100 arasinda bir deger giriniz.");
if (isMistake) {
right++;
System.out.println("Cok fazla hatali giris yaptiniz. Kalan hak : " + (5 - right));
} else {
isMistake = true;
System.out.println("Bir daha hatali girisinizde hakkinizdan dusulecektir.");
}
continue;
}
if (selected == num) {
System.out.println("Tebrikler, dogru tahmin ! Tahmin ettigin sayi : " + num);
isWin = true;
break;
} else {
System.out.println("Hatali bir sayi girdiniz !");
if (selected > num) {
System.out.println(selected + " sayisi, gizli sayidan buyuktur.");
right++;
} else {
System.out.println(selected + " sayisi, gizli sayidan kucuktur.");
right++;
}
System.out.println("Kalan hakki : " + (5 - right));
}
}
if (!isWin) {
System.out.println("Kaybettin ! ");
}
inp.close();
}
}