-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.java
More file actions
102 lines (100 loc) · 3.4 KB
/
code.java
File metadata and controls
102 lines (100 loc) · 3.4 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package d;
import java.util.Scanner;
public class dddd {
public static void main (String args[]) {
Boolean a1 = true;
while (a1==true) {
Scanner in = new Scanner(System.in);
System.out.println("Введите интервал:");
String type = in.next();
OpredChisel chislo = new OpredChisel();
Ugad ch = new Ugad();
chislo.chisla = type;
chislo.Preobraz();
int a=0;
ch.ugad();
System.out.println("Вы загадали число "+ch.rand+"? В случае правильного ответа введите 'Да', иначе введите '>' или '<'");
while ((type.equals("Да")) != true) {
type = in.next();
if (type.equals(">")) {
ch.bol();
System.out.println("Вы загадали число " + ch.rand + "? В случае правильного ответа введите 'Да', иначе введите '>' или '<'");
}
if (type.equals("<")) {
ch.men();
System.out.println("Вы загадали число " + ch.rand + "? В случае правильного ответа введите 'Да', иначе введите '>' или '<'");
}
a++;
}
System.out.println("Ура! Количество итераций поиска составило - " + a + " Сыграем еще раз? Введите 'да' или 'нет'");
type = in.next();
if (type.equals("нет")){
a1=false;
}
}
}
}
class OpredChisel{
String chisla;
String a="";
private int b;
String c="";
static int ch1;
static int ch2;
void Preobraz() {
for (int i = 0; i < chisla.length(); i++) {
if (chisla.charAt(i)!='-'){
a =a+ chisla.charAt(i);
}else {
b=i+1;
break;
}
}
ch1 = Integer.valueOf(a);
for (int i = b; i < chisla.length(); i++) {
c = c + chisla.charAt(i);
}
ch2 = Integer.valueOf(c);
}
}
//class Ugad{ //ТАКОЙ СЕБЕ МЕТОД УГАДЫВАНИЯ, НО НА НЕГО БЫЛА НАДЕЖДА, ЗАЧЕМ ТЫ МЕНЯ ПОДВЕЛ БРАТ
// private int min;
// private int max;
// static int rand;
// void ugad(){
// max=OpredChisel.ch2;
// min=OpredChisel.ch1;
// rand= (int) (Math.random() * ((max-min)+1)) + min;
// System.out.println(min+" "+max+" "+rand);
// }
// void bol(){
// min=Ugad.rand;
// System.out.println(min+" "+max+" "+rand);
// rand= (int) (Math.random() * ((max-min)+1)) + min;
// }
// void men(){
// max=Ugad.rand;
// System.out.println(min+" "+max+" "+rand);
// rand= (int) (Math.random() * ((max-min)+1)) + min;
// }
//}
class Ugad{
private int low;
private int high;
static int rand;
void ugad(){
high=OpredChisel.ch2;
low=OpredChisel.ch1;
rand = (low + high) / 2;
}
void bol(){
high=OpredChisel.ch2;
low=rand+1;
rand = (low + high) / 2;
}
void men(){
high=rand-1;
low=OpredChisel.ch1;
rand = (low + high) / 2;
}
}