Menu
Topics Index
...
`

Creating File


If you need explanation Read this topic

If you need Answer Take test on this topic

Creating File
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();
    }
}

A. 1.0,9.1,3.0,4.0,5.1,7.1,
B. 1.0,9.1,3.0,4.0,5.1,7.1,2.6,
C. 9.1,5.1,7.1,2.6,
D. 9.1,5.1,7.1,
E. Compilation Error or 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 a.
while loop prints upto 7.1,
aft tat hasnxtdoubl conditn faild thn conditn goes out of loop bcz of break .

Posted by Maheshwari Natarajan    2014-07-03 13:06:42


Ans is A. All the contents are written to the file and while reading it treats each number as double and prints till 7.1.After 7.1 it is a string and not a numeral, so while loop breaks

Posted by Nikhil Sulibhavi    2014-07-03 13:09:48


Ans is A..it wl print the data from file until it encounters the char...

Posted by Uday Kumar    2014-07-03 13:10:31


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

Posted by Merit Campus    2014-07-04 04:30:36


© meritcampus 2019

All Rights Reserved.

Open In App