Lowest price ever! Learn Generative AI for 48% less!
Get my discount+ 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.