Results 1 to 2 of 2
  1. #1
    Java_Man is offline Member
    Join Date
    Feb 2008
    Posts
    2
    Rep Power
    0

    Default Here is my code, can anyone here help me?

    import java.util.Scanner;
    import java.lang.*;



    public class ByteMonitor {

    public ByteMonitor() {
    }

    public static void main(String[] args) {

    Scanner scanner = null;

    try {
    scanner = new Scanner(new File("my_file.dat")); }
    catch (FileNotFound ex) {
    ex.printStackTrace(); }

    Pattern file = Pattern.compile("x");
    Matcher mfile = file.matcher("1001x000");
    Matcher mfile = file.matcher("11111011");
    Matcher m_2_file = file.matcher("00x00000");
    Matcher m_3_file = file.matcher("00000000");
    Matcher m_4_file = file.matcher("1001000x");
    boolean x0 = mfile.matches();
    boolean x1 = m1file.matches();
    boolean x2 = m2file.matches();
    boolean x3 = m3file.matches();
    boolean x4 = m4file.matches();


    System.out.println(scanner.nextLine());
    }
    }

    -----------

    I'm trying to get the result to print out this...

    x
    null
    x
    null
    x

    so if anyone here can edit and help me what I did wrong and fix my code, I would greatly appreciate it, thanks.

  2. #2
    CaptainMorgan's Avatar
    CaptainMorgan is offline Moderator
    Join Date
    Dec 2007
    Location
    NewEngland, US
    Posts
    835
    Rep Power
    8

    Default

    When posting source code, use the code tags available in the post Reply page. Or "[ code]" to start code and "[ /code]" to end code. This presents your code in more easily viewable way.

    Quote Originally Posted by Java_Man View Post
    import java.util.Scanner;
    import java.lang.*;
    The java.lang is imported by default- this is the base of the Java language. Thus you don't need it. But you're missing an import for some of the classes you're using. For example, where do you find Pattern and Matcher? Go to the API and look if you do not know. While you're there, please tell me where you find the exception "FileNotFound". On this one, I'll be easier- the correct name is "FileNotFoundException". See the difference?

    I'm trying to get the result to print out this...

    x
    null
    x
    null
    x
    Well, what does your my_file.dat have in it?

    so if anyone here can edit and help me what I did wrong and fix my code, I would greatly appreciate it, thanks.
    No. The problem you're having is syntactic in nature. We're not here to "fix" your code- the majority of us are here to assist you with your Java programming issues. I spoke briefly of the issues you're currently having, now get to it. If it doesn't compile after you've attempted it, come back and post your updated code again(with code tags).
    Vote for the new slogan to our beloved Java Forums! (closes on September 4, 2008)
    Want to voice your opinion on your IDE/Editor of choice? Vote now!
    Got a little Capt'n in you? (drink responsibly)

Similar Threads

  1. Need help with my code.
    By stormviper in forum New To Java
    Replies: 8
    Last Post: 11-18-2013, 03:58 PM
  2. I need help fixing my code.. or non code?
    By MrHuggykins in forum New To Java
    Replies: 1
    Last Post: 03-19-2008, 10:12 PM
  3. Pls some one to help mi wit this code
    By _nik_ in forum New To Java
    Replies: 3
    Last Post: 02-10-2008, 02:02 AM
  4. tic tac toe code
    By zoe in forum New To Java
    Replies: 1
    Last Post: 07-23-2007, 04:36 PM
  5. Replies: 1
    Last Post: 04-26-2007, 03:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •