package Question; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; public class Main { public static void main(String[] args) throws FileNotFoundException { Scanner scan = new Scanner(new FileReader("src/pyramid.txt")); String whl = ""; // taking input from txt file while (scan.hasNextLine()){ whl += scan.nextLine() + "\n"; } String []pyramid_row = whl.split("\n"); int size = pyramid_row.length; // size of pyramid int [][]matrix = new int[size][pyramid_row[size-1].length()]; int k = 0; for (int i=0; i matrix[i+1][ind+1] ? matrix[i+1][ind] : matrix[i+1][++ind]; sum+=max; } } } return sum; } }