Java Urgent: Resolve Java Error - Single Quote Character Outputting æ

AI Thread Summary
A user encountered an issue in Java where using System.out.print to display a single quote resulted in an unexpected character (æ) instead of the correct apostrophe in output. The problem was traced back to copying code from Microsoft Word, which altered the formatting and introduced "smart quotes." The solution involved manually re-entering the apostrophe directly into the code, which resolved the issue. It was emphasized that using word processors like Microsoft Word for coding is problematic due to automatic formatting changes. Instead, it is recommended to use plain text editors or IDEs specifically designed for programming to avoid such issues.
Deathfish
Messages
80
Reaction score
0
Hi, I am programming a command line program in Java. When I try to use System.out.print to print a single quote character, it outputs æ instead. So I get output like

Johnæs height is 1.72 m

instead of John's height is 1.72m

I tried using escape sequence and i get illegal escape character error.

Previously it was working fine but I don't know what happened. Please help, thanks!
 
Technology news on Phys.org
Ah yes, this does happen sometimes. Can you post the code so that I may take a closer look?

System.out.printf("John's height is 1.72 m");

That should work, however sometimes it seems like the encoding gets messed up for some reason. An alternative would be for you to use the unicode value for the apostrophe. It's not the best method, but it'll work. The unicode value for the apostrophe is \u2019

System.out.printf("John\u2019s height is 1.72m");

If you can post the code, I'll take a closer look at it, but for now, the aforementioned solution works.
 
Thanks! think i figured it out...

I realized I was copying to and from Microsoft Word, think the formatting got copied over too... I deleted the character and keyed in via keyboard myself and it works fine now
 
You're welcome.

Writing code in Microsoft Word is a big no no. You can change the format of Microsoft Word to Plain Text format, but you're better off writing your code in notepad if you have a Windows, or whatever Notepad's equivalent on the Mac is.

I personally prefer writing my code directly into my IDE, for Java, I favor Eclipse.
 
I don't think it was a matter of formatting, more like Word changed ' to something else, just like it automatically changes between dash and hyphen in some cases. There are several similarly looking punctuation marks - apostrophe, prime and single quotation mark (perhaps even more).
 
Deathfish said:
Thanks! think i figured it out...

I realized I was copying to and from Microsoft Word, think the formatting got copied over too

You probably have "smart quotes" switched on in MS Word (the default setting is on). That will turn the ' and " characters you typed into opening and closing quotes like ‘...’ and “...”, which is a good idea when writing a report, but not when writing program code!

If you really want to edit your code in Word, the best way is to save it as a text file. But using an editor designed for writing programs, that doesn't mess with what you type, is a better way to go.
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Back
Top