import java.io.*; import java.util.Scanner; public class Opgaver { public static void main(String[] args) throws FileNotFoundException { Opgave1.opgave1(); //Opgave2.opgave2(); } } class Opgave1 { public static void opgave1() throws FileNotFoundException { Scanner file = new Scanner(new File("problem2.html")); boolean inTag = false; while (file.hasNextLine()) { Scanner currentLine = new Scanner(file.nextLine()); String stringInTag = ""; String textOnLine = ""; inTag = false; while (currentLine.hasNext()) { String token = currentLine.next(); for (int i = 0; i < token.length(); i++) { if (inTag == false && token.charAt(i) == '<') { inTag = true; } else if (inTag == true && token.charAt(i) == '>') { inTag = false; stringInTag = ""; continue; } if (inTag == false) { textOnLine += token.charAt(i); } else { stringInTag += token.charAt(i); } } textOnLine += (inTag ? "" : " "); } System.out.println(textOnLine + stringInTag); } } public static String readEntireFile(Scanner input) { String stringFile = ""; while (input.hasNextLine()) { stringFile += input.nextLine() + "\n"; } return stringFile; } } class Opgave2 { public static void opgave2() throws FileNotFoundException { Scanner console = new Scanner(System.in); System.out.print("Indtast filnavn/sti: "); String fileName = console.next(); Scanner file = new Scanner(new File(fileName)); int sum = 0; int amount = 0; int max = 0; int min = 0; while (file.hasNext()) { if (file.hasNextInt()) { int token = file.nextInt(); amount++; sum += token; min = (amount == 1 ? token : min); // Min-værdien skal defineres som første tal. min = (token < min ? token : min); // Min-værdien opdateres hvis token er større end den. max = (amount == 1 ? token : max); // Samme som min. max = (token > max ? token : max); } else { file.next(); } } System.out.println("Gennemsnittet er: " + (double) sum / amount); System.out.println( "Min.-værdien er : " + min + " og Maks-værdien er: " + max ); } }