-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathZoo.java
41 lines (34 loc) · 1.12 KB
/
Zoo.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
/*
Problem
You are required to enter a word that consists of x and y that denote the number of Zs and Os respectively. The input word is considered similar to word zoo if 2*x=y.
Determine if the entered word is similar to word zoo.
For example, words such as zzoooo and zzzoooooo are similar to word zoo but not the words such as zzooo and zzzooooo.
Input format
First line: A word that starts with several Zs and continues by several Os.
Note: The maximum length of this word must be 20.
Output format
Print Yes if the input word can be considered as the string zoo otherwise, print No
*/
import java.util.Scanner;
class Zoo{
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int z=0, o=0;
String str=sc.nextLine();
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)=='z')
{
z++;
}
else
o=o+1;
}
if(z*2==o)
{
System.out.println("Yes");
}
else
System.out.println("No");
}
}