-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFamily_game.java
51 lines (49 loc) · 1.19 KB
/
Family_game.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
45
46
47
48
49
50
51
public class Family_game {
public static void main(String[]args)
{
int n=3;
Boolean b[]=new Boolean[n];
char ch[]={'x','y','x'};
int i=0,j=0;
while(i<n)
{
b[i]=true; //--------Set all the player true
i++;
}
while(n!=1)
{
for( i=0;n>1;) //Alternative for(i=0;i<b.length()&&n!==1)
{
if(b[i]==true)
{
if(ch[j]=='y')
{
b[i]=false;
n--;
j++;
}
else{
j++;
}
}
i++;
if(i>=b.length)
{
i=0;
}
if(j==ch.length)
{
j=0;
}
}
}
for(int a=0;a<b.length;a++)
{
if(b[a]==true)
{
System.out.println(a+1);
break;
}
}
}
}