How to print a superscript text in java..? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to print a superscript text in java..?

I desperately needed to print a mathematical formula like Y=x^2 + K ... How to print it by a print line.. System.out.println(?);

5th Dec 2018, 1:27 PM
Yasas Sandeepa
Yasas Sandeepa - avatar
9 Answers
+ 6
You can use unicode For example if you need x^2 write System.out.print("x\u00b2");
5th Dec 2018, 2:10 PM
Michal
Michal - avatar
+ 13
Yasas Sandeepa //Try this , direct power 2 in superscript 👍 System.out.println("Y=x"+(char)253+"+k"); edit : (in SL playground) // Michal method (I have putted his way in code , might not showing here but will show in other playground) // A new thing learned , thanks Michal ☺ https://code.sololearn.com/cPAqy855Fn86/?ref=app
6th Dec 2018, 2:45 AM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 11
//94 describe character ^ : ● System.out.println("Y=x"+(char)94+"2+k");
5th Dec 2018, 2:15 PM
Gaurav Agrawal
Gaurav Agrawal - avatar
+ 4
Michal bro u are a genius...!!!🙏🔥👍❤ Thank you very much..
6th Dec 2018, 1:50 AM
Yasas Sandeepa
Yasas Sandeepa - avatar
+ 3
Yasas Sandeepa I'm glad that I could help. // Gaurav Agrawal that's kinda interesting way to do this using the chars 🤔
6th Dec 2018, 8:07 AM
Michal
Michal - avatar
+ 2
Use it: double mathFormula = Math.pow(x,2) + k; System.out.println(mathFormula);
5th Dec 2018, 8:25 PM
Kristy 🍀
Kristy 🍀 - avatar
+ 2
Gaurav Agrawal Thanks for your kind concern..but I want to print the power of x not the ^ symbol..Please can u give a support??
6th Dec 2018, 1:48 AM
Yasas Sandeepa
Yasas Sandeepa - avatar
+ 2
Kristy31 Thanks for your answer..but I don't want to print the answer and just want to superscript the number..like as Michal done it..Thanks once again..
6th Dec 2018, 1:56 AM
Yasas Sandeepa
Yasas Sandeepa - avatar
+ 1
Gaurav Agrawal it's not working bro..Michal gave the correct answer -->"x\u00b2" ..btw I really appreciate ur kind responses..Thanks once again
6th Dec 2018, 3:36 AM
Yasas Sandeepa
Yasas Sandeepa - avatar