Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 6 of 6

Thread: help in java i cant compile this

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default help in java i cant compile this

    hi to all i am new to java and i am doing homework
    i must compile this but there is an error and i cant find were
    can you help me please
    i am using BlueJ and jdk

    import java.io.*;
     
    public class IO_Tester {
     
        public static int readInt() {
           byte b[] = new byte[16];
           String str;
     
           try{
               System.in.read(b);
               str = (new String(b)).trim();
               return Integer.parseInt(str);
        }   catch (IOException e) {
            System.out.println("Exception: " + e.toString());
            return 0;
    }
    }
    }
        public static float readFloat() {
            byte b[] = new byte[16];
            String str;
     
            try{
                System.in.read(b);
                str = (new String(b)).trim();
                return Float.parseFloat(str);
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return 0;
            }
        }
     
        public static String readString() {
            byte b[] = new byte[32];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                return str;
            }   catch(IOException e) {
                System.out.println("Exception: ")+e.toString());
                return "";
            }
        }
     
        public static boolean readBoolean() {
            byte b[] = new byte[16];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                Boolean bool = new Boolean(str);
                return bool.booleanValue();
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return false;
            }
        }


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help in java i cant compile this

    Hey timeline,

    Welcome to the Java Programming Forums

    There were a few small errors in your code. This should work:

    import java.io.*;
     
    public class IO_Tester {
     
        public static int readInt() {
           byte b[] = new byte[16];
           String str;
     
           try{
               System.in.read(b);
               str = (new String(b)).trim();
               return Integer.parseInt(str);
        }   catch (IOException e) {
            System.out.println("Exception: " + e.toString());
            return 0;
    }
    }
     
        public static float readFloat() {
            byte b[] = new byte[16];
            String str;
     
            try{
                System.in.read(b);
                str = (new String(b)).trim();
                return Float.parseFloat(str);
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return 0;
            }
        }
     
        public static String readString() {
            byte b[] = new byte[32];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                return str;
            }   catch(IOException e) {
                System.out.println("Exception: " +e.toString());
                return "";
            }
        }
     
        public static boolean readBoolean() {
            byte b[] = new byte[16];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                Boolean bool = new Boolean(str);
                return bool.booleanValue();
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return false;
            }
        }
     
    }

    I've highlighted the errors below:

    import java.io.*;
     
    public class IO_Tester {
     
        public static int readInt() {
           byte b[] = new byte[16];
           String str;
     
           try{
               System.in.read(b);
               str = (new String(b)).trim();
               return Integer.parseInt(str);
        }   catch (IOException e) {
            System.out.println("Exception: " + e.toString());
            return 0;
    }
    }
    [B]}[/B]
        public static float readFloat() {
            byte b[] = new byte[16];
            String str;
     
            try{
                System.in.read(b);
                str = (new String(b)).trim();
                return Float.parseFloat(str);
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return 0;
            }
        }
     
        public static String readString() {
            byte b[] = new byte[32];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                return str;
            }   catch(IOException e) {
                System.out.println[B]("Exception: ")+e.toString());[/B]
                return "";
            }
        }
     
        public static boolean readBoolean() {
            byte b[] = new byte[16];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                Boolean bool = new Boolean(str);
                return bool.booleanValue();
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return false;
            }
        }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. The Following User Says Thank You to JavaPF For This Useful Post:

    timeline (April 15th, 2010)

  4. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: help in java i cant compile this

    thank for the help
    import java.io.*;
     
    public class IO_Tester {
     
        public static int readInt() {
           byte b[] = new byte[16];
           String str;
     
           try{
               System.in.read(b);
               str = (new String(b)).trim();
               return Integer.parseInt(str);
        }   catch (IOException e) {
            System.out.println("Exception: " + e.toString());
            return 0;
    }
    }
     
        public static float readFloat() {
            byte b[] = new byte[16];
            String str;
     
            try{
                System.in.read(b);
                str = (new String(b)).trim();
                return Float.parseFloat(str);
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return 0;
            }
        }
     
        public static String readString() {
            byte b[] = new byte[32];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                return str;
            }   catch(IOException e) {
                System.out.println("Exception: "+e.toString());
                return "";
            }
        }
     
        public static boolean readBoolean() {
            byte b[] = new byte[16];
            String str;
     
            try {
                System.in.read(b);
                str = (new String(b)).trim();
                Boolean bool = new Boolean(str);
                return bool.booleanValue();
            }   catch (IOException e) {
                System.out.println("Exception: " +e.toString());
                return false;
            }
        }
    }

  5. #4
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help in java i cant compile this

    Did this solve your issue timeline?
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  6. #5
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: help in java i cant compile this

    yes thanks a lot

  7. #6
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: help in java i cant compile this

    Quote Originally Posted by timeline View Post
    yes thanks a lot
    Glad I could help. I am marking this thread as solved.
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Game of Craps: won't compile
    By FreeBird in forum What's Wrong With My Code?
    Replies: 9
    Last Post: February 15th, 2010, 05:12 PM
  2. need help to compile
    By hardwarewizard in forum Java Theory & Questions
    Replies: 0
    Last Post: February 14th, 2010, 10:03 AM