1. 程式人生 > 其它 >unity筆記(指令碼1)

unity筆記(指令碼1)

public class test01 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int length = scanner.nextInt();

        int tempInt[] = new int[length];

        int max = 0;
        int tempMax = 0;

        for (int i = 0; i < length; i++) {
    今天的課堂測試讓我體會到邏輯思維和資料結構演算法在寫程式碼中的重要性。       

 tempInt[i] = scanner.nextInt();

            if (i == 0) {
                tempMax = tempInt[i];
                max = tempInt[i];
            } else {
                if (tempMax < 0) {
                    tempMax = tempInt[i];
                } else {
                    tempMax += tempInt[i];
                }
            }

            if (tempMax > max) {
                max = tempMax;
            }
        }

        System.out.println(max);

    }
}