-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_097_EqualsJavaPython.java
More file actions
39 lines (33 loc) · 1012 Bytes
/
_097_EqualsJavaPython.java
File metadata and controls
39 lines (33 loc) · 1012 Bytes
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
package Repl_it_Tasks;
import java.util.Scanner;
public class _097_EqualsJavaPython {
/*
* Given a string, print out true if the number of appearances of "java"
* anywhere in the string is equal to the number of appearances of "python"
* anywhere in the string (case sensitive).
*
* Example: input: We study java not python output: true
*
* Example: input: What's the difference between java, javascript and python?
* output: false
*/
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
String sentence = scan.nextLine();
int javaCount = 0;
int pythonCount = 0;
for (int i = 0; i < sentence.length() - 3; i++) {
if (sentence.substring(i, (i+4)).equals("java"))
javaCount += 1;
}
for (int k = 0; k < sentence.length() - 5; k++) {
if (sentence.substring(k, (k+6)).equals("python"))
pythonCount += 1;
}
if (javaCount != pythonCount) {
System.out.println("false");
} else {
System.out.println("true");
}
}
}