ABCheck.java
· 613 B · Java
Raw
// code for ABCHeck question
import java.util.*;
import java.io.*;
class Main {
public static String ABCheck(String str) {
str = str.toLowerCase(); // Make case insensitive
for (int i = 0; i < str.length() - 4; i++) {
if ((str.charAt(i) == 'a' && str.charAt(i + 4) == 'b') ||
(str.charAt(i) == 'b' && str.charAt(i + 4) == 'a')) {
return "true";
}
}
return "false";
}
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.print(ABCheck(s.nextLine()));
}
}
1 | // code for ABCHeck question |
2 | import java.util.*; |
3 | import java.io.*; |
4 | |
5 | class Main { |
6 | |
7 | public static String ABCheck(String str) { |
8 | str = str.toLowerCase(); // Make case insensitive |
9 | for (int i = 0; i < str.length() - 4; i++) { |
10 | if ((str.charAt(i) == 'a' && str.charAt(i + 4) == 'b') || |
11 | (str.charAt(i) == 'b' && str.charAt(i + 4) == 'a')) { |
12 | return "true"; |
13 | } |
14 | } |
15 | return "false"; |
16 | } |
17 | |
18 | public static void main(String[] args) { |
19 | Scanner s = new Scanner(System.in); |
20 | System.out.print(ABCheck(s.nextLine())); |
21 | } |
22 | } |
23 |