Java 通过提示用户输入垂直显示文本字符串

Java 通过提示用户输入垂直显示文本字符串,java,Java,我希望能够垂直显示文本字符串,例如垂直显示“Hello”: H E L L o 我有一个方法(void)来显示两个单词,但它不能正确地显示它 public class VerticalString { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //prompt the user to input a string String s=new String();

我希望能够垂直显示文本字符串,例如垂直显示“Hello”: H E L L o

我有一个方法(void)来显示两个单词,但它不能正确地显示它

public class VerticalString {

    BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); //prompt the user to input a string
    String s=new String();     
    String sa[]; 
    int count=0,maxwl=0;

     void input()throws Exception //
        {
              System.out.print("ENTER THE SENTENCE TO PRINT AS VERTICAL STRING :");
            s=br.readLine();
            sa=new String[s.length()];
        }

     void ArrayStore() //array store to temporaily store data
            {
                Scanner sc=new Scanner(s);
                while(sc.hasNext())
                {
                    sa[count++]=sc.next();
                    if(sa[count-1].length()>maxwl)
                      maxwl=sa[count-1].length();
                }
            }

     void PrintVertical() //method to create vertical string
            {
                System.out.println("THE VERTICAL STRING IS :\n");
                for(int i=0;i<maxwl;i++)
                {
                    for(int j=0;j<count;j++)
                    {
                        if(i<sa[j].length())
                             System.out.print(format("%s",sa[j].charAt(i)+" "));
                        else
                             System.out.println("\n");
                    }
                    System.out.println();
                }
            }
    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws Exception {
        // TODO code application logic here
        VerticalString obj = new VerticalString();
        obj.input();
        obj.ArrayStore();
        obj.PrintVertical();
    }

}
公共类垂直字符串{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));//提示用户输入字符串
字符串s=新字符串();
字符串sa[];
整数计数=0,最大值=0;
void input()引发异常//
{
System.out.print(“输入要打印的句子作为垂直字符串:”);
s=br.readLine();
sa=新字符串[s.length()];
}
void ArrayStore()//临时存储数据的数组存储
{
扫描仪sc=新的扫描仪;
while(sc.hasNext())
{
sa[count++]=sc.next();
if(sa[count-1].length()>maxwl)
maxwl=sa[count-1]。长度();
}
}
void PrintVertical()//创建垂直字符串的方法
{
System.out.println(“垂直字符串为:\n”);

对于(int i=0;i,这里是我的命题:

void PrintVertical() // method to create vertical string
{
    System.out.println("THE VERTICAL STRING IS :\n");
    for (int i = 0; i < maxwl; i++) {
        for (int j = 0; j < count; j++) {
            if ( i<sa[j].length() ) {
                System.out.print(sa[j].charAt(i));
            }
            else {
                System.out.print(" ");
            }
        }
        System.out.println();
    }
}
void PrintVertical()//创建垂直字符串的方法
{
System.out.println(“垂直字符串为:\n”);
对于(int i=0;i