`Inline Code Example Here`
    import java.io.*;
    import java.util.regex.*;



        String []str = {"123","0959","75443","19908","1","11879","1119","276","566777","7","675","4435","54","6588","99","124","78"};
        String filename = "temp.text";

         try{
         File file = new File(filename);
         FileWriter fw = new FileWriter(file);
         for(int i=1;i<=str.lenght;i++){ // Start for
         BufferedWriter bw = new BufferedWriter(fw);
         bw.write(str);
         bw.newLine();
             } // End for
          bw.close();
          }catch(IOException ex){
                    System.out.println("Error.."+filename+" ");
                                }

          public void Search_Digit(String str){ // Start serch
            String line = "";
            try{ // Start try
            FileReader file = new FileReader(filename);
            BufferedReader br = new BufferedReader(file);
            while ((line = br.readLine()) !=null)
            { // Start while
            System.out.println(line);
            } // End while
            br.close();

            Pattern p = Pattern.compile("(\\d+){3}");
            Matcher m = p.matcher(line);
            while(m.find()){
            System.out.println( "Found" + m.group(1));

            } // End while
            }catch(FileNotFoundException ex){
                System.out.println("Unable to open File "+filename+"");
                                     }
                catch(IOException ex){
                System.out.println("ERROR WRITING TO FILE"+ filename +"");
                             }

               } // End search

     public static void main(String[]args){

         Find_digit obj = new Find_digit();
           obj.Search_Digit(str);
     }
    }

All Java code is part of a class definition - you have forgotten/lost the class statement that should be around line 5. Similarly the code starting a t line 10 should be inside a method definion.
Now look again at the error message that you got but decided not to show us - did it say something about "class" expected? Next time post a copy of the complete error message(s).

Edited 3 Years Ago by JamesCherrill

Thank for your amswer but i write the class

public class Find_digit That's it

and this is the error i recived

C:\Users\jody\Desktop\Find_digit.java:7: error: illegal start of type
     try{
     ^
C:\Users\jody\Desktop\Find_digit.java:7: error: ';' expected
     try{
        ^
C:\Users\jody\Desktop\Find_digit.java:10: error: illegal start of type
     for(int i=1;i<=str.lenght;i++){ // Start for
     ^
C:\Users\jody\Desktop\Find_digit.java:10: error: ')' expected
     for(int i=1;i<=str.lenght;i++){ // Start for
              ^
C:\Users\jody\Desktop\Find_digit.java:10: error: illegal start of type
     for(int i=1;i<=str.lenght;i++){ // Start for
               ^
C:\Users\jody\Desktop\Find_digit.java:10: error: <identifier> expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                ^
C:\Users\jody\Desktop\Find_digit.java:10: error: ';' expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                 ^
C:\Users\jody\Desktop\Find_digit.java:10: error: illegal start of type
     for(int i=1;i<=str.lenght;i++){ // Start for
                  ^
C:\Users\jody\Desktop\Find_digit.java:10: error: ';' expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                       ^
C:\Users\jody\Desktop\Find_digit.java:10: error: <identifier> expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                              ^
C:\Users\jody\Desktop\Find_digit.java:10: error: <identifier> expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                                ^
C:\Users\jody\Desktop\Find_digit.java:10: error: illegal start of type
     for(int i=1;i<=str.lenght;i++){ // Start for
                                  ^
C:\Users\jody\Desktop\Find_digit.java:10: error: <identifier> expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                                   ^
C:\Users\jody\Desktop\Find_digit.java:10: error: ';' expected
     for(int i=1;i<=str.lenght;i++){ // Start for
                                    ^
C:\Users\jody\Desktop\Find_digit.java:11: error: <identifier> expected
     BufferedWriter bw = new BufferedWriter(fw);
                      ^
C:\Users\jody\Desktop\Find_digit.java:12: error: <identifier> expected
     bw.write(str);
             ^
C:\Users\jody\Desktop\Find_digit.java:12: error: <identifier> expected
     bw.write(str);
                 ^
C:\Users\jody\Desktop\Find_digit.java:13: error: <identifier> expected
     bw.newLine();
               ^
C:\Users\jody\Desktop\Find_digit.java:15: error: class, interface, or enum expected
      bw.close();
      ^
C:\Users\jody\Desktop\Find_digit.java:16: error: class, interface, or enum expected
      }catch(IOException ex){
      ^
C:\Users\jody\Desktop\Find_digit.java:18: error: class, interface, or enum expected
                                }
                                ^
C:\Users\jody\Desktop\Find_digit.java:20: error: class, interface, or enum expected
      public void Search_Digit(String s){ // Start serch
             ^
C:\Users\jody\Desktop\Find_digit.java:22: error: class, interface, or enum expected
        try{ // Start try
        ^
C:\Users\jody\Desktop\Find_digit.java:24: error: class, interface, or enum expected
        BufferedReader br = new BufferedReader(file);
        ^
C:\Users\jody\Desktop\Find_digit.java:25: error: class, interface, or enum expected
            while ((line = br.readLine()) !=null)
            ^
C:\Users\jody\Desktop\Find_digit.java:28: error: class, interface, or enum expected
        } // End while
        ^
C:\Users\jody\Desktop\Find_digit.java:31: error: class, interface, or enum expected
        Pattern p = Pattern.compile("(\\d+){3}");
        ^
C:\Users\jody\Desktop\Find_digit.java:32: error: class, interface, or enum expected
                Matcher m = p.matcher(str);
                ^
C:\Users\jody\Desktop\Find_digit.java:33: error: class, interface, or enum expected
        while(m.find()){
        ^
C:\Users\jody\Desktop\Find_digit.java:36: error: class, interface, or enum expected
        } // End while
        ^
C:\Users\jody\Desktop\Find_digit.java:40: error: class, interface, or enum expected
                                         }
                                         ^
C:\Users\jody\Desktop\Find_digit.java:43: error: class, interface, or enum expected
                         }
                         ^
C:\Users\jody\Desktop\Find_digit.java:47: error: class, interface, or enum expected
 public static void main(String[]args){
               ^
C:\Users\jody\Desktop\Find_digit.java:50: error: class, interface, or enum expected
           obj.Search_Digit(str);
           ^
C:\Users\jody\Desktop\Find_digit.java:51: error: class, interface, or enum expected
 }
 ^
35 errors

Tool completed with exit code 1

please help me to correct this error because this is
HW Ishould finished Quickly

I do it now but give me another error

C:\Users\jody\Desktop\Find_digit.java:13: error: cannot find symbol
               for(int i=1;i<=str.lenght;i++){ // Start for
                                 ^
  symbol:   variable lenght
  location: variable str of type String[]
C:\Users\jody\Desktop\Find_digit.java:15: error: no suitable method found for write(String[])
               bw.write(str);
                 ^
    method BufferedWriter.write(String,int,int) is not applicable
      (actual and formal argument lists differ in length)
    method BufferedWriter.write(char[],int,int) is not applicable
      (actual and formal argument lists differ in length)
    method BufferedWriter.write(int) is not applicable
      (actual argument String[] cannot be converted to int by method invocation conversion)
    method Writer.write(String) is not applicable
      (actual argument String[] cannot be converted to String by method invocation conversion)
    method Writer.write(char[]) is not applicable
      (actual argument String[] cannot be converted to char[] by method invocation conversion)
C:\Users\jody\Desktop\Find_digit.java:18: error: cannot find symbol
                bw.close();
                ^
  symbol:   variable bw
  location: class Find_digit
C:\Users\jody\Desktop\Find_digit.java:33: error: method matcher in class Pattern cannot be applied to given types;
                Matcher m = p.matcher(str);
                             ^
  required: CharSequence
  found: String[]
  reason: actual argument String[] cannot be converted to CharSequence by method invocation conversion
C:\Users\jody\Desktop\Find_digit.java:51: error: non-static variable str cannot be referenced from a static context
           obj.Search_Digit(str);
                            ^
C:\Users\jody\Desktop\Find_digit.java:51: error: method Search_Digit in class Find_digit cannot be applied to given types;
           obj.Search_Digit(str);
              ^
  required: String
  found: String[]
  reason: actual argument String[] cannot be converted to String by method invocation conversion
6 errors

Tool completed with exit code 1

Can you rewrite the correct code to me

Because I does not know how to do it the right way

Let's start with the first two...

Lines 2/4 - a spelling error
Lines 6-18 - you can't just make up your own method calls for BufferedWriter like that. Look at the API doc for BufferedWriter to see what parameters you can actually pass to its write methods

I got bored after that, but a quick look further down has more of the same errors. You MUST check the API doc to find out what parameters are valid for each method call.

Edited 3 Years Ago by JamesCherrill

I'm sorry I know I disturbed you, but I do not know how do it :(
I'm not good at programming sufficiently

I'm not good at programming sufficiently

I guess that's why you are on a programming course! It's not easy, so it's up to you if you want to do all the necessary work.
Anyway, if you want to keep trying then start with the very first error message, read carefully what it says, and fix it. Then re-compile, fix the first error, and keep repeating that until there are no errors left. Your first error is a spelling mistake, so that should be easy to fix ;)

Thanks alot for all answer

I'm try very much now i have 3 error can i post it now

now this is the new cod

import java.io.*;
import java.util.regex.*;

public class Find_digit{
    String filename = "temp.text";

      public void Search_Digit(){ // Start serch
      try{
      String []s = {"123","0959","75443","19908","1","11879","1119","276","566777","7","675","4435","54","6588","99","124","78"};

           File file = new File(filename);
           FileWriter fw = new FileWriter(file);
           for(int i=1;i<=18;i++){ // Start for
           BufferedWriter bw = new BufferedWriter(fw);
           bw.write(s);
           bw.newLine();
               } // End for
            bw.close();
            }catch(IOException ex){
                    System.out.println("Error.."+filename+" ");
                            }
        String line = " ";
        try{ // Start try
        FileReader file = new FileReader(filename);
        BufferedReader br = new BufferedReader(file);
        while ((line = br.readLine()) !=null)
        { // Start while
        System.out.println(line);
        } // End while
        br.close();

        Pattern p = Pattern.compile("(\\d+){3}");
        Matcher m = p.matcher(s);
        while(m.find()){
        System.out.println( "Found" + m.group(1));

        } // End while
        } // End try
        catch(FileNotFoundException ex){
            System.out.println("Unable to open File "+filename+"");
                                 }
            catch(IOException ex){
            System.out.println("ERROR WRITING TO FILE"+ filename +"");
                         }

           } // End search

 public static void main(String[]args){
     Find_digit obj = new Find_digit();
     obj.Search_Digit();
 }
}

and this is the error

C:\Users\jody\Desktop\Find_digit.java:15: error: no suitable method found for write(String[])
               bw.write(s);
                 ^
    method BufferedWriter.write(String,int,int) is not applicable
      (actual and formal argument lists differ in length)
    method BufferedWriter.write(char[],int,int) is not applicable
      (actual and formal argument lists differ in length)
    method BufferedWriter.write(int) is not applicable
      (actual argument String[] cannot be converted to int by method invocation conversion)
    method Writer.write(String) is not applicable
      (actual argument String[] cannot be converted to String by method invocation conversion)
    method Writer.write(char[]) is not applicable
      (actual argument String[] cannot be converted to char[] by method invocation conversion)
C:\Users\jody\Desktop\Find_digit.java:18: error: cannot find symbol
                bw.close();
                ^
  symbol:   variable bw
  location: class Find_digit
C:\Users\jody\Desktop\Find_digit.java:33: error: cannot find symbol
                Matcher m = p.matcher(s);
                                      ^
  symbol:   variable s
  location: class Find_digit
3 errors

Tool completed with exit code 1

What is wrong now :(

Find_digit.java:15: error: no suitable method found for write(String[])

On line 15 of Find-digit you try to call a write method passing a String array as parameter, but there is no write method that takes a string array.

Did you read the previous posts?

You MUST check the API doc to find out what parameters are valid for each method call.

just check the api for BufferedWriter as James suggested

I became crazy I done everything I know to fix it
But I could not fixed

please what can I do ??

no suitable method found for write(String[])
               bw.write(s);

that means that the method you try to call doesn't exist. either not with that name, or not with that signature. check the api to see which one(s) DO exist and you can use.

as for your other errors: it seams you are trying to use variables that either don't exist, or are out of the scope.

Thanks alot for your answer
now i understand what you say about the error
but the problem is idon't know how it solved

i am sorry i tired you

Let me make this very clear for you:

We do not do people's homework for them.
We are not a free "we write your code for you" service.

If you want help to learn Java then you will get that help here. If you are not willing to listen and work and learn then please stop wasting eveybody's time.

thanks for your help my brother
and i'm very sorry if i inconvenience we
i really want to learn java and i dont want to anybody to do my HW
but really i'm not very good in java program so i search for help
finally i thank evrybody help me here and i'm sorry again .

This article has been dead for over six months. Start a new discussion instead.