输出以字符串形式提升到幂的数字 [英] Output a number raised to a power as a string

查看:140
本文介绍了输出以字符串形式提升到幂的数字的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Java的新手,我不太确定如何将一个整数提升到一个幂作为字符串输出。我知道

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

Math.pow(double, double)

实际上会计算一个加倍功率的值。但是如果我想输出2 ^ 6作为输出(除了6作为上标而不是克拉),我该怎么做?

will actually compute the value of raising a double to a power. But if I wanted to output "2^6" as an output (except with 6 as a superscript and not with the carat), how do I do that?

编辑:这适用于Android应用。我将整数提升到一个字符串的幂,我想知道如何在手机的UI中将其转换为上标。

This is for an Android app. I'm passing in the integer raised to the power as a string and I would like to know how to convert this to superscript in the UI for the phone.

推荐答案

如果您要将文本输出到GUI,那么您可以使用 HTML格式 < sup> 标记获取上标。否则,您将必须使用Unicode字符来获取其他上标。维基百科有一篇关于Unicode上标和下标的好文章:

If you're outputting the text to the GUI then you can use HTML formatting and the <sup> tag to get a superscript. Otherwise, you'll have to use Unicode characters to get the other superscripts. Wikipedia has a nice article on superscripts and subscripts in Unicode:

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

这篇关于输出以字符串形式提升到幂的数字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆