I have a project due where I have to draw an inverted triangle using the for loop, however I have to use the word that the person inputed to make the triangle.
So... the output should look like this...
Enter a word: hello
hello
hell
hel
he
h
however...
mine looks like this
Enter a word: hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
hello
The code I printed looks like this:
System.out.println("Enter a word");
Scanner keyboard = new Scanner(System.in);
String a = keyboard.nextLine();
int rows = a.length()-1;
for(int i = rows; i > 0; i--){
for(int j = i; j > 0; j--){
System.out.println(a);
}
}
I tried to search up how to fix it online, but the only thing that comes up is how to make triangles using * signs, but that doesn't seem to work when using words.
If anyone could help me figure out to get the above result it would be greatly appreciated.
question from:
https://stackoverflow.com/questions/65947090/inverted-triangle 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…