用java编写菱形/菱形的单词

用java编写菱形/菱形的单词,java,printing,shape,Java,Printing,Shape,我必须编写一个程序,询问一个单词,然后以菱形/菱形打印,如下所示: Word: Hello H He Hel Hell Hello ello llo lo o import java.util.Scanner; public class Rhombus { public static void main(String[] args) { Scanner sc = new Scanner(System.in); System.out

我必须编写一个程序,询问一个单词,然后以菱形/菱形打印,如下所示:

Word: Hello
H
He
Hel
Hell
Hello
 ello
  llo
   lo
    o
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));

        }
    }
}
我尝试了一些东西,但如果有人可以的话,我真的需要一些帮助,我尝试了这样的东西:

Word: Hello
H
He
Hel
Hell
Hello
 ello
  llo
   lo
    o
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));

        }
    }
}
import java.util.Scanner;
公共类菱形{
公共静态void main(字符串[]args){
扫描仪sc=新的扫描仪(System.in);
系统输出打印(“字:”);
字符串字=sc.nextLine();
int wordLength=word.length();
for(int i=0;i
给您:

public static void main(String[] args) {
    printRhombusText("yolobird");
}

public static void printRhombusText(String s) {
    // top part
    for (int i = 1; i <= s.length(); ++i) {
        System.out.println(s.substring(0, i));
    }
    // bottom part
    for (int i = 1; i <= s.length(); ++i) {
        // print out the space
        for (int y = i; y > 0; --y) {
            System.out.print(" ");
        }
        System.out.println(s.substring(i));
    }
}
编辑 要添加用户输入吗? 在这里:

输出:

Input your text: kiet
k
ki
kie
kiet
 iet
  et
   t

You want to do one more? (y/n): y
Input your text: ahihi
a
ah
ahi
ahih
ahihi
 hihi
  ihi
   hi
    i

You want to do one more? (y/n): n

请提供语法正确的代码。我如何在这里实现输入法?就像它问你一个字,然后每个字都会这样做@屠ấ恩基ệT