-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdoubleX.java
More file actions
30 lines (29 loc) · 799 Bytes
/
Copy pathdoubleX.java
File metadata and controls
30 lines (29 loc) · 799 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
/*
Given a string, return true if the first instance of "x"
in the string is immediately followed by another "x".
*/
package codingbat;
import java.util.*;
public class doubleX {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String str;
int j, flag = 0;
System.out.print("Enter a string: ");
str = sc.nextLine();
for(int i = 0; i < str.length(); i++){
j = i+1;
if (str.charAt(i) == 'x'){
if (str.charAt(j) == 'x'){
flag = 1;
}
}
}
if (flag == 1){
System.out.println("True!");
}
else{
System.out.println("False!");
}
}
}