import   java.io.*; 
public  class bb 

       public static void main(String [] args) throws Exception 
       { 
          int x=c; 
          byte[] br = new byte[100]; 
          System.out.println("请输入一串字符:") 
          InputStream is = System.in; 
              InputStreamReader isr=new InputStreamReader(is); 
              BufferedReader br=new BufferedReader(isr); 
              String str=br.readLine(); 
              char[] ch=new char[str.length()]; 
              str.getChars(0, str.length(), ch, 0); 
              for(int a=0;a<str.length();a++) 
               { 
                if (str==null) 
                { 
            throw   new   IllegalArgumentException("参数数组c为空"); 
            System.exit(0);    
                } 
              if(str[a]=x)  
                { 
               System.out.println(a); 
                } 
              else 
                { 
               System.out.println("-1"); 
                }  
              
               } 
       } 

错误  
--------------------Configuration: <Default>-------------------- 
G:\java\lesson1\bb.java:9: ';' expected 
              InputStream is = System.in; 
                  ^ 
1 error Process completed.  
 

解决方案 »

  1.   

    int x=c; 
              byte[] br = new byte[100]; 
              System.out.println("请输入一串字符:");
              InputStream is = System.in; 
    仅仅是改了这个错误 能不能正常运行你先试试再说
      

  2.   

    import   java.io.*; import java.io.BufferedReader;
    public  class bb 

           public static void main(String [] args) throws Exception 
           { 
                  char  x='c';
                
                  
               
                  System.out.println("请输入一串字符:") ;
                  InputStream is = System.in; 
                  InputStreamReader isr=new InputStreamReader(is); 
                  BufferedReader br=new BufferedReader(isr); 
                  String str=br.readLine(); 
                 // char[] ch=new char[str.length()]; 
                  //str.getChars(0, str.length(), ch, 0); 
                  for(int a=0;a<str.length();a++) 
                   { 
                    if (str==null) 
                    {
                      System.exit(0);    
                      } 
                    
                    
                   if(str.charAt(a)==x)  
                    { 
                       System.out.println(a); 
                    } 
                    else 
                    { 
                       System.out.println("-1"); 
                       
                    }  
                  
                   } 
           } 

    可以了
    只是 if(str.charAt(a)==x)  是单个字母比较的 怎样让他从一个字符串里逐个比较