@@ -0,0 +1,2596 @@
+%0Aimport java.io.File;%0Aimport java.io.FileNotFoundException;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport java.util.Scanner;%0Aimport javax.swing.JOptionPane;%0A%0A/**%0A * Using%0A * %3Ca href=%22https://projecteuler.net/project/resources/p022_names.txt%22%3Enames.txt%3C/a%3E,%0A * a 46K text file containing over five-thousand first names, begin by sorting%0A * it into alphabetical order. Then working out the alphabetical value for each%0A * name, multiply this value by its alphabetical position in the list to obtain%0A * a name score.%0A *%0A * For example, when the list is sorted into alphabetical order, COLIN, which is%0A * worth 3 + 15 + 12 + 9 + 14 = 53, is the 938th name in the list. So, COLIN%0A * would obtain a score of 938 %C3%97 53 = 49714.%0A *%0A * What is the total of all the name scores in the file?%0A *%0A * @author Matthew Van der Bijl%0A */%0Apublic final class Problem_22 implements Runnable %7B%0A%0A    public static void main(String%5B%5D args) %7B%0A        new Problem_22().run();%0A    %7D%0A%0A    @Override%0A    public void run() %7B%0A        List%3CString%3E names = new ArrayList%3C%3E();%0A        final String alphabet = %22abcdefghijklmnopqrstuvwxyz%22.toUpperCase();%0A%0A        try %7B%0A            Scanner sc = new Scanner(new File(%22p022_names.txt%22));%0A            while (sc.hasNextLine()) %7B%0A                String ln%5B%5D = sc.nextLine().split(%22%5C%22%22);%0A                for (int i = 1; i %3C ln.length; i += 2) %7B%0A                    names.add(ln%5Bi%5D);%0A                %7D%0A            %7D%0A            sc.close();%0A        %7D catch (FileNotFoundException fnfe) %7B%0A            System.err.println(fnfe);%0A        %7D%0A%0A        for (int i = 0; i %3C names.size(); i++) %7B%0A            for (int j = i; j %3C names.size(); j++) %7B%0A                if (names.get(i).compareTo(names.get(j)) %3E 0) %7B%0A                    String temp = names.get(j);%0A                    names.set(j, names.get(i));%0A                    names.set(i, temp);%0A                %7D%0A            %7D%0A        %7D%0A//        %0A//        for (String name : names) %7B%0A//            System.out.println(name);%0A//        %7D%0A//        %0A        long totalScore = 0;%0A        for (int i = 0; i %3C names.size(); i++) %7B%0A            int score = 0;%0A            for (int j = 0; j %3C names.get(i).length(); j++) %7B%0A                for (int k = 0; k %3C alphabet.length(); k++) %7B%0A                    if (names.get(i).charAt(j) == alphabet.charAt(k)) %7B%0A                        score += k + 1;%0A                        break;%0A                    %7D%0A                %7D%0A            %7D%0A            totalScore += score * (i + 1);%0A        %7D%0A%0A//        System.out.println(totalScore);%0A        JOptionPane.showMessageDialog(null, totalScore);%0A    %7D%0A%7D%0A

Create Problem_22.java