Regular Expression Check (aa)*+(aaa)*
package regularexpression.check;
import java.util.Scanner;
public class RegularExpressionCheck {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“The R.E is (aa)*+(aaa)*”);
System.out.println(“Enter the string”);
String str = sc.nextLine();
System.out.println(“The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol “);
int length = str.length();
int flag=0;
System.out.println(“length =” + length);
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println(“The R.E is (aa)*+(aaa)*”);
System.out.println(“Enter the string”);
String str = sc.nextLine();
System.out.println(“The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol “);
int length = str.length();
int flag=0;
System.out.println(“length =” + length);
for (int i = 0; i < length; i++) {
if(str.charAt(i)!=’a’)
{
flag=1;
if(str.charAt(i)!=’a’)
{
flag=1;
}
else
{ if(length%2==0||length%3==0||str.isEmpty())
{
flag=2;
else
{ if(length%2==0||length%3==0||str.isEmpty())
{
flag=2;
}
else
{
flag=1;
else
{
flag=1;
}
}
}
if(flag==2||str.contains(“e”)|| str.isEmpty())
{
System.out.println(“RE ACCEPTED”);
}
else
{
System.out.println(“RE REJECTED”);
}
}
}
if(flag==2||str.contains(“e”)|| str.isEmpty())
{
System.out.println(“RE ACCEPTED”);
}
else
{
System.out.println(“RE REJECTED”);
}
OUTPUT
The R.E is (aa)*+(aaa)*
Enter the string
Enter the string
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =0
RE ACCEPTED //since no char inserted
length =0
RE ACCEPTED //since no char inserted
The R.E is (aa)*+(aaa)*
Enter the string
e
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =1
RE ACCEPTED //e represents epsilline
Enter the string
e
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =1
RE ACCEPTED //e represents epsilline
The R.E is (aa)*+(aaa)*
Enter the string
aaaaa
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =5
RE REJECTED
Enter the string
aaaaa
The condition for R.E is to have a in multiple of 2 or 3 or no a and no other symbol
length =5
RE REJECTED
No comments:
Post a Comment