import java.util.*;
public class prac9
{
public static void main(String[] args){
Scanner scn=new Scanner(System.in);
int count=0;
String x,str=" ";
System.out.println("Regular Expression is (a+b)(ab+ba)*");
System.out.println("Enter a Word: ");
x=scn.nextLine(); //here simple x string type of varible
if(x[0]=="a"|| x[0]=="b") //here x array of string type of varible
{ //prac9.java:15: error: array
// required,but String found
for(int i=1; i<x.length(); i++)
{
str+=x[i];
if((i%2==0)==true)
{
if(str=="ab" || str=="ba")
{
count=count+2;
str=" ";
}
}
}
if((count+1)==(x.length())){
System.out.println("Acceptable");
}
else{
System.out.println("Not Acceptable");
}
}
else{
System.out.println("Not Acceptable..");
}
}
できるだけ簡単に私を助けてください。上記のコメントで述べたように、エラーが発生します。私はそれが何を言っているのかを知っていますが、ユーザーが指定したすべての文字をチェックできるように、文字列を配列に変換する方法を理解できません。実際、このコードはC ++で書かれています。Java言語に変換したところです。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加