Page 1 of 2 12 LastLast
Results 1 to 20 of 27
  1. #1
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default How to I print a symbol?

    I am writing a basic program to practise my if statements.

    The program involves money and therefore I need to be able to print the symbol.
    When I use it I don't get a symbol as the output, I get a u with an accent on the top of it.

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: How to I print a symbol?

    Where are you getting the 'u'?
    Is it in the console?
    In the IDE?
    In a Swing component?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    .paul. is offline Member
    Join Date
    Jun 2012
    Posts
    73
    Blog Entries
    1
    Rep Power
    0

    Default Re: How to I print a symbol?

    Java Code:
    import java.text.*;
    Java Code:
    NumberFormat formatter = NumberFormat.getCurrencyInstance();
    System.out.println(formatter.format(number));

  4. #4
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: How to I print a symbol?

    And where is it printing out to?
    And is that place able to display a sign?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  5. #5
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How to I print a symbol?

    urm... I am very new to this so I didn't understand much of what any of you said.

    This is my code:

    Java Code:
    class Gambling {													// Text on this side of the screen indicates lines where you must enter your own information
    
    	public static void main(String[] args) {
    
    	String UserName = "????????";										// Enter your name here (Within speech marks)
    	int Age = ????????;											// Enter your age here
    
    	System.out.println("Hello " + UserName + ",");
    
    		if (Age < 18) {
    		System.out.println("You are too young to use this program, please quit it now.");
    		return;
    		}
    			else {
    			int wallet = ????????;									// Enter your wallet value here (Full pounds only)
    			int bet = ????????;									// Enter your bet here (Full pounds only)
    				if (wallet < bet) {
    				System.out.println("You cannot bet more money than you have in your wallet!");
    				return;
    				}
    					else {
    					System.out.println("You currently have " + wallet + "in your wallet");
    					System.out.println("You have made a bet of" + bet);
    					System.out.println("You have lost the bet!");
    					wallet = wallet - bet;
    					System.out.println("You now have " + wallet + "in your wallet");
    					}
    			}
    	}
    
    }

    I type it in notepad, compile it with the CMD and then run it in the CMD

  6. #6
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    It looks like you want to use the Scanner class to accept input from the user.

    Also, how does this program compile? ???????? is not a valid int value.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: How to I print a symbol?

    I'm just trying to figure out where you're not seeing the sign.
    Different applications can use different character sets, some of which might map characters differently.
    So exactly where you are seeing the problem is quite important.
    And that can include version numbers.
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  8. #8
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    I believe this sequence will produce the sign that you are looking for: "\u20ac"
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  9. #9
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: How to I print a symbol?

    Quote Originally Posted by awinston View Post
    I believe this sequence will produce the sign that you are looking for: "\u20ac"
    Not if the output device isn't able to display it, no.

    db
    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  10. #10
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    Quote Originally Posted by DarrylBurke View Post
    Not if the output device isn't able to display it, no.

    db
    Since he said that he is running it via the command prompt, it should work, right? I tested it using my command prompt and it works for me.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  11. #11
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to I print a symbol?

    Quote Originally Posted by awinston View Post
    Since he said that he is running it via the command prompt, it should work, right? I tested it using my command prompt and it works for me.
    It only tells that your shell/terminal/command prompt can display unicode code points; the OPs terminal may not do so.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  12. #12
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    Quote Originally Posted by JosAH View Post
    It only tells that your shell/terminal/command prompt can display unicode code points; the OPs terminal may not do so.

    kind regards,

    Jos
    Okay, but it's worth a shot.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  13. #13
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to I print a symbol?

    Quote Originally Posted by awinston View Post
    Okay, but it's worth a shot.
    No, programming has nothing to do with shots in the dark, nor is mystery, magic or religion involved; programming is a branch of mathematics and should be practised as such; anything else is (ignorant) guesswork.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  14. #14
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How to I print a symbol?

    Quote Originally Posted by awinston View Post
    It looks like you want to use the Scanner class to accept input from the user.

    Also, how does this program compile? ???????? is not a valid int value.
    I'm using it just as a placeholder so that I can easily see where I need to enter custom values at the moment, I change it before compiling.


    Quote Originally Posted by Tolls View Post
    I'm just trying to figure out where you're not seeing the sign.
    Different applications can use different character sets, some of which might map characters differently.
    So exactly where you are seeing the problem is quite important.
    And that can include version numbers.
    I'm using the CMD in Windows 7 Home Premium with Service Pack 2 which is the CMD version 6.1.7601

    Quote Originally Posted by awinston View Post
    I believe this sequence will produce the sign that you are looking for: "\u20ac"
    I'll try it in a second, thanks

  15. #15
    kkid is offline Senior Member
    Join Date
    Jul 2012
    Posts
    241
    Rep Power
    3

    Default Re: How to I print a symbol?

    \u20ac doesn't work, it gives me a weird C symbol instead

    -gca7d.jpg
    Attached Thumbnails Attached Thumbnails -tjuiz.jpg  
    Last edited by kkid; 08-02-2012 at 08:59 PM. Reason: added image and did a bit of debugging

  16. #16
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,658
    Blog Entries
    7
    Rep Power
    21

    Default Re: How to I print a symbol?

    Have a look at this little unicode table. That code point doesn't represent a pound sterling sign, not even in Unicode; your command prompt doesn't display unicode characters; first you have to figure out what encoding it uses so you can send that code point to it to display a pound sterling symbol.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

  17. #17
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    Quote Originally Posted by JosAH View Post
    No, programming has nothing to do with shots in the dark, nor is mystery, magic or religion involved; programming is a branch of mathematics and should be practised as such; anything else is (ignorant) guesswork.

    kind regards,

    Jos
    I certainly didn't mean to suggest invoking magic, religion, or even shots in the dark, and I apologize if I gave that impression. If he tried it and it worked, then he would know that his CMD can interpret Unicode (and he would have the solution to his problem.) If it didn't work (which is the case), then he would need to find another solution as you suggested.
    Last edited by awinston; 08-02-2012 at 10:04 PM.
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  18. #18
    DarrylBurke's Avatar
    DarrylBurke is offline Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,423
    Rep Power
    20

    Default Re: How to I print a symbol?

    If you're forever cleaning cobwebs, it's time to get rid of the spiders.

  19. #19
    awinston is offline Student
    Join Date
    Jul 2012
    Location
    United States
    Posts
    328
    Rep Power
    3

    Default Re: How to I print a symbol?

    I managed to find a solution involving characters. All credit goes to someone of the username "arthurp" on this thread (it's the 6th post).

    Java Code:
    char a = 339;
    System.out.println("You currently have " + a + wallet + " in your wallet!");
    "Success is not final, failure is not fatal: it is the courage to continue that counts." - Winston Churchill

  20. #20
    anandkesari01 is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: How to I print a symbol?

    Try out this
    System.out.println((char)163);

Page 1 of 2 12 LastLast

Similar Threads

  1. Javax Print Attribute for Selection Print Range
    By rsawatzky in forum AWT / Swing
    Replies: 0
    Last Post: 04-26-2012, 12:14 AM
  2. '@' Symbol
    By AedonetLIRA in forum New To Java
    Replies: 5
    Last Post: 12-09-2010, 01:05 AM
  3. Replies: 9
    Last Post: 10-18-2008, 08:26 PM
  4. Print the text file and print preview them
    By Java Tip in forum java.awt
    Replies: 0
    Last Post: 06-22-2008, 11:04 PM
  5. Replies: 3
    Last Post: 05-01-2008, 08:30 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •