Urgent: Resolve Java Error - Single Quote Character Outputting æ

In summary: Thanks! think i figured it out...In summary, when using System.out.printf to print a single quote character, it outputs æ instead.
  • #1
Deathfish
86
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
  • #2
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.
 
  • #3
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
 
  • #4
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.
 
  • #5
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).
 
  • #6
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.
 

What is causing the Java error related to the single quote character?

The Java error is most likely caused by a coding mistake or a formatting issue with the single quote character. It could also be due to incorrect encoding or a problem with the input data.

How can I fix the Java error and resolve the issue?

To fix the Java error, you will need to carefully review your code and check for any errors related to the single quote character. If the issue persists, you may need to consult the Java documentation or seek help from other developers.

How can I prevent this Java error from occurring in the future?

To prevent this Java error, always make sure to properly format and escape any special characters in your code. It is also important to regularly test and debug your code to catch any potential errors before they become larger issues.

Is this Java error related to a specific version of Java?

There is a possibility that this Java error could be related to a specific version of Java, especially if you are using any new or experimental features. However, it is more likely that the error is caused by a mistake in your code rather than a specific version of Java.

Are there any online resources or forums where I can find help for resolving this Java error?

Yes, there are many online resources and forums where you can find help for resolving Java errors. Some popular options include the Java community forums, Stack Overflow, and various coding blogs and websites. It can also be helpful to reach out to other developers or colleagues for assistance.

Similar threads

  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
4
Views
1K
  • Programming and Computer Science
Replies
4
Views
3K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
1
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
  • Programming and Computer Science
Replies
4
Views
4K
  • Programming and Computer Science
Replies
3
Views
3K
  • Programming and Computer Science
Replies
6
Views
7K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
2K
Back
Top