2016-10-24 10 views
-2
import java.util.*; 
    public class triangle{ 
     public static void main(String args[]){ 
     Scanner input_Obj = new Scanner(System.in); 
     System.out.println("Enter the number of lines in the triangle"); 
     int sum = 0; 
     int mat_size = input_Obj.nextInt(); //input of the size of the triangle 
     System.out.println("enter the inputs"); 
     int input_Array[][] = new int[mat_size][mat_size]; 
     for (int row = 0; row < mat_size; row++){ 
     for (int col = 0; col < col; col++){ 
      input_Array[row][col] = input_Obj.nextInt(); 
     } 
    } 
     if (mat_size >= 3){ 
      int[] sum_array = new int[2*(mat_size-2)]; 
     for (int row = 1; row < mat_size; row++){ 
      for(int col = 0;col<=row;col++){ 
       sum += input_Array[row][col]; 
      } 
      sum_array[row-1] = sum; 
     } 
    } 
     else if(mat_size == 2){ 
      if (input_Array[1][0]<input_Array[1][1]){ 
       System.out.println("minimum of the two elements in second  line is:" +input_Array[1][0]); 
      } 
      else{ 
       System.out.println("minimum of the two elements in second line is:" +input_Array[1][1]); 
      } 
     } 
     else{ 
      System.out.println("minimum sum can't be calculated"); 
     } 
    } 
} 

として与えられた入力を保存しようと、それがmat_sizeで入力を取ったが、私は内部の最小合計を見つけようとしている配列 への入力を取っていない入力配列 に値を格納していません三角形フロイドの三角形

答えて

0
for (int col = 0; col < col; col++) 

col < colは、この条件は、それがどのような入力を取っていない理由がある決して満足しないため、

for (int col = 0; col < mat_size; col++) 
にこの条件を変更する問題です