Menu
Question Index
...

What will be the output of the following program?

import java.io.*;
import java.util.*;
public class FileTest {
    public static void main(String args[]) throws IOException {
        FileWriter fw = new FileWriter("ScanText.txt");
        fw.write("1 9.1 3 4 5.1 7.1 so on 2.6");
        fw.close();
        FileReader fr = new FileReader("ScanText.txt");
        Scanner scanner = new Scanner(fr);
        while (scanner.hasNext()) {
            if (scanner.hasNextDouble()) {
                System.out.print(scanner.nextDouble() + ",");
            } else
                break;
        }
        fr.close();
    }
}


1.0,9.1,3.0,4.0,5.1,7.1,
1.0,9.1,3.0,4.0,5.1,7.1,2.6,
9.1,5.1,7.1,2.6,
9.1,5.1,7.1,
Compilation Error or 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