-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQuestion93_HasAJava.java
More file actions
47 lines (32 loc) · 1016 Bytes
/
Question93_HasAJava.java
File metadata and controls
47 lines (32 loc) · 1016 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
40
41
42
43
44
45
46
47
package week6_String;
import java.util.Scanner;
public class Question93_HasAJava {
public static void main(String[] args) {
// olcay // Jul 8, 2020
/* Given a string word, print true if "java" appears starting at index 0 or 1 in the string,
such as with "javaxxx" or "xjavaxx" but not "xxjavaxx". The string may be any length, including 0word = .
*/
/*Example:
input: javapython
output: true
Example:
input: cjavac++
output: true
Example:
input: c#javaruby
output: false*/
boolean exists = false;
Scanner scan = new Scanner(System.in);
System.out.println("Enter a word: ");
String word = scan.next();
if(word.length()>3) {
if(word.substring(0, 4).equals("java") || word.substring(1, 5).equals("java")) {
System.out.println(!exists);
}else {
System.out.println(exists);
}
}else {
System.out.println(exists);
}
}
}