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.
Printable View
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.
Where are you getting the 'u'?
Is it in the console?
In the IDE?
In a Swing component?
Code:import java.text.*;
Code:NumberFormat formatter = NumberFormat.getCurrencyInstance();
System.out.println(formatter.format(number));
And where is it printing out to?
And is that place able to display a £ sign?
urm... I am very new to this so I didn't understand much of what any of you said.
This is my code:
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
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 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 believe this sequence will produce the sign that you are looking for: "\u20ac"
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.
I'm using the CMD in Windows 7 Home Premium with Service Pack 2 which is the CMD version 6.1.7601
I'll try it in a second, thanks
\u20ac doesn't work, it gives me a weird C symbol instead
Attachment 4018
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
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.
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).
Code:char a = 339;
System.out.println("You currently have " + a + wallet + " in your wallet!");
Try out this
System.out.println((char)163);