Results 1 to 5 of 5
  1. #1
    shroomiin is offline Member
    Join Date
    Sep 2009
    Posts
    31
    Rep Power
    0

    Default Displaying variables in a string?

    Hello everyone. im obviously new to java but im having some trouble displaying some predefined variables i have. I am supposed to write a simple program to compare 2 numbers and then display the larger number following the text "is larger"...this is my code thus far. It gives me trouble in the line where i have to display the variable number with "is larger". cant figure out how i would display this...

    int number1;
    int number2;
    int sum;

    System.out.print( "Enter first integer:");
    number1 = input.nextInt();

    System.out.print ("Enter second integer:");
    number2 = input.nextInt();

    if (number1 == number2)
    System.out.print("These numbers are equal.");

    if (number1 > number2)
    System.out.print(number1," is larger.");

    if (number2 > number1)
    System.out.print(number2," is larger.");



    the red is what im having trouble with..

  2. #2
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    Change
    Java Code:
    System.out.print(number1," is larger.");
    to
    Java Code:
    System.out.print(number1 + " is larger.");

  3. #3
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,409
    Rep Power
    25

    Default

    Also look at using the println() method if you want the output on separate lines.

  4. #4
    shroomiin is offline Member
    Join Date
    Sep 2009
    Posts
    31
    Rep Power
    0

    Default

    ahh, thanks alot for the help!

  5. #5
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

Similar Threads

  1. What are Instance variables and static variables?
    By sandeshforu in forum New To Java
    Replies: 3
    Last Post: 09-09-2009, 05:48 PM
  2. combine string[] into string like perl's join function
    By tekberg in forum Advanced Java
    Replies: 9
    Last Post: 02-23-2009, 01:05 PM
  3. Replies: 5
    Last Post: 01-11-2009, 10:12 AM
  4. displaying string
    By jamborta in forum AWT / Swing
    Replies: 6
    Last Post: 01-23-2008, 07:15 PM
  5. Replies: 0
    Last Post: 11-20-2007, 04:59 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
  •