Hello!
I'm creating a program with the source code below. It doesn't work, because it seems to jump over the while-loop. The code:
public class Ordjaktsfusk { public static void main(String[] args)throws FileNotFoundException, IOException { int plats2, plats3; String finalOrd = ""; BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Vilka bokstäver? "); String bok = in.readLine(); Scanner fil = new Scanner(new File("ord.txt")); while (fil.hasNext()) { String testOrd = fil.nextLine(); hittaOrd: if (bok.charAt(0) == testOrd.charAt(0)) { if(testOrd.indexOf(bok.charAt(1))>-1) { plats2 = testOrd.indexOf(bok.charAt(1)); plats3 = testOrd.indexOf(bok.charAt(2)); } else { break hittaOrd; } if(plats3>plats2) { if (testOrd.length()>finalOrd.length()) { finalOrd = testOrd; } } else { break hittaOrd; } } } System.out.println(finalOrd); } }