Java for循环中的子字符串()导致;StringIndexOutOfBoundsException:字符串索引超出范围:-1“;

Java for循环中的子字符串()导致;StringIndexOutOfBoundsException:字符串索引超出范围:-1“;,java,for-loop,substring,Java,For Loop,Substring,有人能解释这种奇怪的行为吗?谢谢 你的第二个for循环从“input”开始倒计时,只要值是你的第二个for循环从“input”开始倒计时,只要值是for(count=input;countfor(count=input;countfor)(count=input;count非常感谢!刚刚学习Java,请原谅新手的错误!:)非常感谢!刚刚学习Java,请原谅新手的错误!:)这家伙解决了他的问题…我是现在有问题的人:)这家伙解决了他的问题…我是现在有问题的人:) public class Aster

有人能解释这种奇怪的行为吗?谢谢

你的第二个for循环从“input”开始倒计时,只要值是你的第二个for循环从“input”开始倒计时,只要值是for(count=input;countfor(count=input;countfor)(count=input;count非常感谢!刚刚学习Java,请原谅新手的错误!:)非常感谢!刚刚学习Java,请原谅新手的错误!:)这家伙解决了他的问题…我是现在有问题的人:)这家伙解决了他的问题…我是现在有问题的人:)
public class Asterisk
{
    public static void main(String[] args)
    { 
        String output="";
        int count=1, input;

        System.out.println("Input the size of the triangle from 1 to 50:");
        input = 5;

        for(count=1;count <= input;count++)
        {   
                    output += "*";
            System.out.println(output);
        }

        input -= 1;

        for(count =input;count <= input;count--)
        {   
                    output = output.substring(0,count);
            System.out.println(output);
        }
    }
}
    at java.lang.String.substring(String.java:1937)

    at Asterisk.main(Asterisk.java:18)
for(count =input;count <= input;count--) input <= input