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

    Default Need help. I am not able to get the desired display of output in my program.

    Here is my sample program.

    import java.io.*;

    public class trial1{

    public static InputStreamReader reader = new InputStreamReader (System.in);
    public static BufferedReader input = new BufferedReader(reader);

    public static void main(String[]args)throws Exception{

    String num1 = "";
    String num3 = "";
    int num0=0;
    int num2=0;

    while (num0<10) {


    System.out.print("Enter numbers a: ");
    num0 = Integer.parseInt(input.readLine());
    num1+=num0;

    System.out.print("Enter numbers b: ");
    num2 = Integer.parseInt(input.readLine());
    num3+=num2;


    }
    System.out.println(num1+num3);
    } }

    // Example input
    // Enter numbers a: 1
    // Enter numbers b: 3
    // Enter numbers a: 6
    // Enter numbers b: 4
    // Enter numbers a: 11
    // Enter numbers b: 9

    // Output:
    // 1611349

    // Desired output:
    // 1 3
    // 6 4
    // 11 9

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,891
    Rep Power
    25

    Default Re: Need help. I am not able to get the desired display of output in my program.

    If you want two numbers to print instead of the sum of the numbers you need to insert a String between the numbers:
    (1 + " " + 2) will give "1 2"
    (1+2) will give "3"

Similar Threads

  1. Help with output display please
    By DMarsh12 in forum New To Java
    Replies: 3
    Last Post: 10-08-2011, 08:03 AM
  2. Netbeans output window won't display
    By jujubinaj in forum New To Java
    Replies: 1
    Last Post: 12-16-2010, 03:51 AM
  3. How to display Output String in asterix?
    By shalini_priya in forum New To Java
    Replies: 1
    Last Post: 11-24-2009, 12:36 PM
  4. Replies: 0
    Last Post: 11-17-2009, 07:36 PM
  5. Display output in Jframe or JPanel
    By rammurugesan in forum AWT / Swing
    Replies: 12
    Last Post: 04-14-2009, 02:45 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
  •