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 3 of 3

Thread: Add a dollar sign to a number

  1. #1
    Member
    Join Date
    Mar 2012
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Add a dollar sign to a number

    Hi,

    I'm writing a basic program that requires the user to input a number. When the input is printed, I would like to add a dollar sign to it. mu code is as follows:

    class Corruption
    {
        public static void main(String[] args)
        {
     
            ConsoleReader console = new ConsoleReader(System.in);
            System.out.println("Please enter the amount") ;
            int sec = console.readInt();          
            System.out.println(sec + "is the amount you entered");
     
     
        }
    }

    How do I give sec a $ at the beginning? Any help greatly is appreciated.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: Add a dollar sign to a number

    How did you add text to the end of the number?
    Do the same thing to add text to the front...
    Or use printf or format

  3. #3
    Member
    Join Date
    Mar 2012
    Posts
    37
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Add a dollar sign to a number

    print.out.format worked, thanks.

Similar Threads

  1. How do you add a value to a 2-d array by row number and column number?
    By JohnEliot in forum Java Theory & Questions
    Replies: 1
    Last Post: April 14th, 2013, 06:39 AM
  2. Dollar Rate
    By kanna39 in forum Java Theory & Questions
    Replies: 0
    Last Post: November 3rd, 2012, 05:50 AM
  3. Finding all Permutations that add up to a number.
    By godsfearme in forum What's Wrong With My Code?
    Replies: 0
    Last Post: December 28th, 2010, 03:54 PM
  4. sign XML with WS-Security
    By splendes in forum Java SE APIs
    Replies: 1
    Last Post: October 6th, 2010, 08:49 AM
  5. How do I privately sign my applet?
    By AlphaWhelp in forum Java Theory & Questions
    Replies: 1
    Last Post: December 16th, 2009, 09:42 AM