+ 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(?);
9 odpowiedzi
+ 6
You can use unicode
For example if you need x^2 write
System.out.print("x\u00b2");
+ 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
+ 11
//94 describe character ^ :
● System.out.println("Y=x"+(char)94+"2+k");
+ 4
Michal bro u are a genius...!!!🙏🔥👍❤ Thank you very much..
+ 3
Yasas Sandeepa I'm glad that I could help.
// Gaurav Agrawal that's kinda interesting way to do this using the chars 🤔
+ 2
Use it:
double mathFormula = Math.pow(x,2) + k;
System.out.println(mathFormula);
+ 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??
+ 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