Print the number raised to power as a string

I'm new to Java, and I'm not quite sure how to output an integer raised as string output. I know that

Math.pow(double, double) 

will actually calculate the value of raising the deuce to power. But if I wanted to output "2 ^ 6" as an output (except 6 as superscript, not carat), how to do this?

EDIT: This is an Android app. I pass an integer raised to power as a string, and I would like to know how to convert it to superscript in the user interface for the phone.

+1
java android numbers
source share
3 answers

If you output text to a graphical interface, you can use HTML formatting and the <sup> tag to get a superscript. Otherwise, you will have to use Unicode characters to get other superscripts. Wikipedia has a good article on superscripts and Unicode indices:

http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

+3
source share

Unicode has superscript numbers from 0 to 9: http://en.wikipedia.org/wiki/Unicode_subscripts_and_superscripts

This should print 2⁢:

  System.out.println("2⁢"); System.out.println("2\u2076"); 
+9
source share

This answer should be used only when using Eclipse (java editor), what is eclipse, it is only support for certain Unicode characters. 1 2 and 3 everything can be done and supported by eclipse, anything else you need to play with eclipse settings that are not too complicated. There, this thing is called Windows-1252, which is used by default for many things, which seem to be the default encoding for files in Eclipse. Thus, whenever you type on the console, this is what it tries to interpret as, and it does not support the full unicode character set, since it encodes 1 byte. This is actually not a problem with Java, it is a problem with Eclipse, which means that you need to edit Eclipse to use UTF-8. You can do this in several places; if you just want Unicode characters to appear when this single file is run, you can right-click the file, properties β†’ resource β†’ encode a text file and change it by default to another: utf-8. If you want to do this in the entire workspace, you can go to Window -> Preferences -> General -> Workspace -> Text file encoding. You can also do this throughout the project, or even just across the entire complex, following fairly similar steps depending on what you are going to do.

0
source share

All Articles