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.


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

Results 1 to 2 of 2

Thread: problem with output

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Thanked 0 Times in 0 Posts

    Default problem with output

    Hello, i have a problem in output, can everyone help me?
    here is my code

                    Scanner in=new Scanner(new File("input.txt"));
    		PrintWriter out=new PrintWriter(new File("output.txt"));
    			out.println(in.next()+" "+in.nextInt()+1);

    input is John 17
    output must be John 18
    but in this programm it is John 171
    can i write this in one line?

  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    United Kingdom
    My Mood
    Thanked 294 Times in 227 Posts
    Blog Entries

    Default Re: problem with output

    Hello Timur,

    Welcome to the Java Programming Forums.

    You were very close with your code. You just needed the extra brackets..

    		Scanner in = new Scanner(new File("input.txt"));
    		PrintWriter out = new PrintWriter(new File("output.txt"));
    		out.println(in.next() + " " + (in.nextInt() + 1));

    I have also moved this thread to the correct forum. Thanks.
    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. JTextArea output problem
    By grimx in forum What's Wrong With My Code?
    Replies: 5
    Last Post: July 8th, 2010, 07:54 PM
  2. Output problem (newbie)
    By Asido in forum What's Wrong With My Code?
    Replies: 5
    Last Post: June 8th, 2010, 12:19 PM
  3. xml output problem
    By tsili in forum Java Theory & Questions
    Replies: 4
    Last Post: May 25th, 2010, 04:56 AM
  4. OutPut.
    By chronoz13 in forum Java Theory & Questions
    Replies: 3
    Last Post: August 29th, 2009, 10:54 AM
  5. Display output from a file using regular expression
    By jazz2k8 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: May 29th, 2008, 09:33 AM