Menu
Question Index
...

What is the output of the following program?

import java.util.*;
import java.io.*;

public class Delemeter {
    public static void main(String[] args) throws IOException {
        int count = 0;
        double sum = 0;
        FileWriter fw = new FileWriter("tet.txt");
        fw.write("2, 1.25,  5, 8,   9.5, etc 10.5, 11");
        fw.close();
        FileReader fr = new FileReader("tet.txt");
        Scanner scanner = new Scanner(fr);
        scanner.useDelimiter(", *");
        while (scanner.hasNext()) {
            sum += scanner.nextDouble();
            count++;
        }
        fr.close();
        System.out.println("Average: " + sum / count);
    }
}


Avegare: 5.15
Avegare: 6.75
Avegare: 7.6
Compilation Error
Runtime Error

Doubts

Problems

Topic: Java FileWriter

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App