I don’t understand why this doesn’t run. I am trying to make a program that displays the text the user inputs as a triangle. Each new line adds a letter which forms the triangle pattern.
For example, if the user enters the word computers, the output would be:
s
sr
sre
sret
sretu
sretup
sretupm
sretupmo
sretupmoc
import java.util.Scanner;
public class BackwordsTri
{
public static void main(String[] arg)
{
Scanner keyboard = new Scanner(System.in);
String word = keyboard.nextLine();
String newWord="";
char ch;
int wl = word.length();
for (int i=0; i < word.length(); i++)
{
int q = (wl - i);
ch= word.charAt(q);
newWord= ch + newWord;
System.out.println(newWord);
}
}
}