I have to write a program that asks a word and then prints it in a rhombus/diamond shape, like this:
Word: Hello
H
He
Hel
Hell
Hello
ello
llo
lo
o
I tried something but I really could use some help if someone could, I tried something like this:
import java.util.Scanner;
public class Rhombus {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Word: ");
String word = sc.nextLine();
int wordLength = word.length();
for (int i = 0; i < wordLength; i++) {
System.out.println(word.substring(0, i));
}
}
}
See Question&Answers more detail:os