Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialDaniel Silva
10,644 PointsHow to output a number raised to the power in Java
Hello, I'm finishing up this application I am writing that displaced the cubic feet of boxes. However it's just printing 355ft. I need it to print 355ft^3 BUT NOT THE "^" SYMBOL. The three needs to be smaller too, since it's cubic feet. Any ideas?
Thanks,
3 Answers
Michael Davis
Courses Plus Student 12,508 PointsIt sounds like, to me, that you are trying to get the 3, representing "cubed", to show as superscript. Displaying text in the superscript or subscript is a formatting task, and as such would require some sort of text manipulation. If your result is going to be displayed in HTML, you can use the <sup></sup> tag to cause it to display in the superscript
style.
As an alternative, you can have the text display as 355 cu-ft
, or if you really want the superscript 3, use the unicode representation '\u00B3'
. If you open your browser's web console and type '\u00B3', including the quotes, you'll get the superscript 3.
Thomas Nilsen
14,957 PointsSystem.out.println(Math.pow(3, 2)); // This is 3 to the power of 2 => 9
Daniel Silva
10,644 PointsSorry I mean I don't need the results. It's how to display it such as 2^ but instead of the '^' sign it it would be a number.
Alexander Davison
65,469 PointsI'm not 100% sure how, but at least in Python you can use the double asterisk, like this: **
Daniel Silva
10,644 PointsI tried it, it didn't work...but thanks anyways for trying to help!
Alexander Davison
65,469 PointsNo problem :P
Srry.