How can I take a String
variable and print it's contents in a diagonal line downward? Preferably using a for
or while
loop.
This is the code I have now, which doesn't work as intended:
String str = JOptionPane.showInputDialog("enter a string");
for(int i = 0; i <= str.length(); i++)
{
System.out.println(str.charAt(i));
}
This outputs str
in a line downwards, but not diagonal. How can I make it look like this:
E
X
A
M
P
L
E