Menu
Topics Index
...
`

Files : Creating FileWriter and FileReader


If you need explanation Read this topic

If you need Answer Take test on this topic

Files : Creating FileWriter and FileReader
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);
    }
}

A. Avegare: 5.15
B. Avegare: 6.75
C. Avegare: 7.6
D. Compilation Error
E. Runtime Error
Topic: Java FileWriter

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans:e

Posted by Nausheen Fathima    2014-06-20 09:14:11


answer e..sum+=scnr.nxtdouble() line throws input mismatch exceptn.
to avoid this excptin we need to giv 1if condintn to chck hasnxt value double or not.

Posted by NagaRaj Nataraj    2014-06-20 09:23:40


Congratulations NagaRaj Nataraj. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-06-23 04:41:25


© meritcampus 2019

All Rights Reserved.

Open In App