Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2
These are workarounds as subscript and superscript are not natively defined in Java. You can use unicode charachters. For example: public static void main(String[] args) { String water = "H\u2082O"; System.out.println(water); } In an HTML environment you could uotput html tags in the string like: public static void main(String[] args) { String water = "H<sub>2</sub>O"; System.out.println(water); } I doubt that this solution work in the code playground.
26th Jan 2017, 3:52 AM
seamiki
seamiki - avatar