Regular Expression (RE)  (a+b)*  and (a+b)*cd Programming In Java.
|  | 
| 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");
}
}
}
  
  
 
 
 
                        
                    
 
  
 
 
 
 
bhai firse accha se details likho
ReplyDelete