package deneme1; import java.nio.file.Path; import java.nio.file.Paths; import java.util.LinkedList; import java.util.Scanner; public class Main { static int sum = 0; static int selectedIndex = 0; public static void main(String[] args) throws Exception{ Path filePath = Paths.get("/Users/Giray/Desktop/test.txt"); Scanner scanner = new Scanner(filePath); LinkedList integersFromFile = new LinkedList(); while (scanner.hasNext()) { if (scanner.hasNextInt()) { integersFromFile.add(scanner.nextInt()); } else { scanner.next(); } } findSum(integersFromFile, findColumnCount(integersFromFile)); System.out.println("Sum is :"+ sum); } // TO FIND HOW MANY COLUMNS ARE THERE IN THE FILE public static int findColumnCount(LinkedList array) { int totalItemCount = array.size(); int firstNumber = 1; int countOfColumns = 0; while (totalItemCount != 0 ) { countOfColumns++; totalItemCount = totalItemCount - firstNumber; firstNumber++; } return countOfColumns; } public static boolean isNonPrime(int number) { if (number <= 1) { return false; } if (number <= 3) { return false; } for (int i = 2; i < number; i++) { if (number % i == 0) { return true; } } return true; } public static void findSum(LinkedList array,int column) { int tempMax = 0; for (int currentColumn=1; currentColumn<=column; currentColumn++) { // FIRST COLUMN if (currentColumn == 1 && isNonPrime(array.get(0))) { sum = sum + array.get(selectedIndex); array.removeFirst(); } // 2 OR MORE BIGGER else if (currentColumn != 1 ) { if (array.get(selectedIndex) > array.get(selectedIndex+1)) { tempMax = array.get(selectedIndex); if (isNonPrime(tempMax)) { sum = sum + tempMax; } } else if (array.get(selectedIndex+1) > array.get(selectedIndex)) { tempMax = array.get(selectedIndex+1); if (isNonPrime(tempMax)) { sum = sum + tempMax; selectedIndex = selectedIndex + 1; } } // FOR DELETING ELEMENTS FROM ARRAY for (int j=0;j