import java.util.Scanner;
public class E000 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the string Satisfying RE:(1+01+001)*(e+0+00)");
String str=sc.nextLine();
int length=str.length();
int count=0,flag=0;
for (int i = 0; i < length; i++)
{
if(str.equals("e"))
{
System.out.println("empty string accepted");
return;
}
else if(str.charAt(i)!='0'&&str.charAt(i)!='1')
{
System.out.println("String does not contain binary digits");
return;
}
}
for (int j = 0; j < length; j++)
{
if (str.charAt(j)=='1')
{
flag=0;
}
else if(str.charAt(j)=='0')
{
flag++;
}
}
if(flag<3||str.contentEquals("e")||str.equals("0")||str.equals("00")||str.equals("1")||str.equals("01"))
{
System.out.println("String Accepted");
}
else
{
System.out.println("String Rejected");
}
}
}
e
empty string accepted
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
5
String does not contain binary digits
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100100
String Accepted
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100000
String Rejected
public class E000 {
public static void main(String[] args) {
Scanner sc= new Scanner(System.in);
System.out.println("Enter the string Satisfying RE:(1+01+001)*(e+0+00)");
String str=sc.nextLine();
int length=str.length();
int count=0,flag=0;
for (int i = 0; i < length; i++)
{
if(str.equals("e"))
{
System.out.println("empty string accepted");
return;
}
else if(str.charAt(i)!='0'&&str.charAt(i)!='1')
{
System.out.println("String does not contain binary digits");
return;
}
}
for (int j = 0; j < length; j++)
{
if (str.charAt(j)=='1')
{
flag=0;
}
else if(str.charAt(j)=='0')
{
flag++;
}
}
if(flag<3||str.contentEquals("e")||str.equals("0")||str.equals("00")||str.equals("1")||str.equals("01"))
{
System.out.println("String Accepted");
}
else
{
System.out.println("String Rejected");
}
}
}
OUTPUTS
Enter the string Satisfying RE:(1+01+001)*(e+0+00)e
empty string accepted
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
5
String does not contain binary digits
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100100
String Accepted
Enter the string Satisfying RE:(1+01+001)*(e+0+00)
100000
String Rejected
No comments:
Post a Comment