-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFinalFirstClass.java
More file actions
51 lines (46 loc) · 1.32 KB
/
FinalFirstClass.java
File metadata and controls
51 lines (46 loc) · 1.32 KB
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
48
49
50
51
import java.util.Scanner;
public class FinalFirstClass {
public static void main(String[] args) {
Scanner scan= new Scanner(System.in);
String word;
int a=0;
System.out.println("Please enter a string : ");
word=scan.nextLine();
if (word.charAt(0)=='a' || (word.charAt(0)=='a' && word.charAt(1)=='a')) {
if (word.length()==1) {
System.out.println(word+" is recognized by a*");
}
else if (word.length()==2) {
System.out.println(word+" is recognized by a*");
}
else if (word.charAt(0)=='a' && word.charAt(1)=='a' && word.charAt(2)=='b' ) {
System.out.println(word+" is recognized by aab");
}
else if (word.length()>=2) {
for (int i = 0; i < word.length()-1; i++) {
if (word.charAt(i)=='a') {
a=1;
}
else if(word.charAt(i)=='a' || word.charAt(i)=='b'){
a=0;
}
}
if (a==1) {
System.out.println(word+" is recognized by a*");
}
else if (a==0) {
System.out.println(word+" is recognized by a*b+");
}
}
else {
System.out.println(word+" is recognized by a*b+");
}
}
else if (word.charAt(0)=='a' && word.charAt(1)=='a' && word.charAt(2)=='b' ) {
System.out.println(word+" is recognized by aab");
}
else {
System.out.println("String can not recogniged");
}
}
}