-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDay14s1.java
More file actions
60 lines (52 loc) · 2.38 KB
/
Day14s1.java
File metadata and controls
60 lines (52 loc) · 2.38 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
59
60
import java.util.Scanner;
/**
* Sayı Tahmin Oyunu
* Bilgisayarın 1-100 arasında tuttuğu rastgele sayıyı tahmin etmeye çalışan basit bir oyun.
*/
public class Day14s1 {
public static void main(String[] args) {
// Rastgele sayı üret (1-100 arası)
int rastgeleSayi = (int) (Math.random() * 100) + 1;
int tahmin = 0;
int denemeSayisi = 0;
boolean dogruTahmin = false;
Scanner scanner = new Scanner(System.in);
System.out.println("*** SAYI TAHMİN OYUNU ***");
System.out.println("1 ile 100 arasında bir sayı tuttum. Tahmin edebilir misin?");
// Doğru tahmin edilene kadar devam et
while (!dogruTahmin) {
System.out.print("Tahmininiz: ");
// Geçerli bir sayı girilip girilmediğini kontrol et
if (scanner.hasNextInt()) {
tahmin = scanner.nextInt();
denemeSayisi++;
// Tahminleri kontrol et
if (tahmin < 1 || tahmin > 100) {
System.out.println("Lütfen 1 ile 100 arasında bir sayı girin!");
} else if (tahmin < rastgeleSayi) {
System.out.println("Daha BÜYÜK bir sayı girin!");
} else if (tahmin > rastgeleSayi) {
System.out.println("Daha KÜÇÜK bir sayı girin!");
} else {
dogruTahmin = true;
System.out.println("\nTEBRİKLER! " + denemeSayisi + " denemede doğru tahmin ettiniz.");
// Performans değerlendirmesi
if (denemeSayisi <= 3) {
System.out.println("Şanslı günündesin! Mükemmel!");
} else if (denemeSayisi <= 7) {
System.out.println("Çok iyi bir skor!");
} else if (denemeSayisi <= 10) {
System.out.println("İyi bir skor.");
} else {
System.out.println("Bir dahaki sefere daha iyi olabilir.");
}
}
} else {
// Geçersiz giriş
System.out.println("Lütfen geçerli bir sayı girin!");
scanner.next(); // Geçersiz girişi temizle
}
}
scanner.close();
}
}