Regular Expression (RE) (a+b)* and (a+b)*cd Programming In Java.
![Regular expression java programe RE (a+b)* and (a+b)*cd](https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhyIUAwKL5nB76dtk8O2w-6-1MLSfbWkBOcyLckC_KTrL9yAX7WJoqwunOPhNnF6EJkNgBGvhPbY_1fSXcQ5GtXd9YB7ecq0oUhx2mHu3vomqqnmITtOg-xbNY0ycjnKXe2OdPPtyPRSQ0/s320/1.jpg) |
Re Java program |
Basic Concept
Algorithm
Program
import java.util.Scanner;
import java.io.*;
class ReContains {
public static void main(String[] args) {
int re1 = 0;
int re2 = 0;
int re1not = 0;
int re2not = 0;
String t;
try {
FileReader f = new FileReader("C:\\Users\\Lab-3\\Documents\\Rajeev\\Re.java");
BufferedReader br = new BufferedReader(f);
while ((t = br.readLine()) != null) {
System.out.println(t);
}
Scanner r = new Scanner(System.in);
System.out.println("enter the String");
String one = r.next();
int i = 0;
while (i < one.length()) {
if (one.charAt(i) == 'a' || one.charAt(i) == 'b') {
i++;
re1++;
}
else {
re1not++;
break;
}
}
for (int j = 0; j < one.length(); j++)
{
if (one.charAt(j) == 'a' || one.charAt(j) == 'b')
{}
else
{
if (one.charAt(j) == 'c' && one.charAt(j + 1) == 'd')
{
re2++;
}
else
re2not++;
break;
}}
} catch (IOException e) {
System.out.println("something error");
}
//for re 2
if (re2 > 0 && re2not == 0)
System.out.println("in the second re");
else {
System.out.println(" not in the second re");
}
//for re1
if (re1 > 0 && re1not == 0)
System.out.println("in the first re");
else {
System.out.println(" not in the first re");
}
}
}
compiler Design
bhai firse accha se details likho
ReplyDelete