Expert Answer
3
34
56
64
35
59
22
23
52
91
8
49
63
59
4
73
100
13
31
7
13
54
44
28
71
92
73
12
78
0
3
58
42
43
43
97
28
35
69
55
55
50
54
71
44
13
18
98
53
15
49
64
38
67
72
46
46
63
6
68
37
66
45
33
46
7
46
94
100
42
30
85
6
11
67
50
96
78
14
51
43
93
56
78
46
21
35
35
97
92
1
21
68
13
18
56
31
99
61
76
___________________
ReadFile100RandomNos.java
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileWriter;
import java.util.Scanner;
public class ReadFile100RandomNos {
public static void main(String[] args) {
int i=0,max,lineNo=0;
int nos[]=new int[100];
Scanner sc;
try {
sc = new Scanner(new File(“D://100Rands.txt”));
while(sc.hasNext())
{
nos[i++]=sc.nextInt();
}
sc.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
int m=0;
max=nos[m];
for(;m<nos.length;m++)
{
if(max<nos[m])
{
max=nos[m];
lineNo=m+1;
}
}
File f = new File(“D:\result.txt”);
FileWriter fw = null;
// creates the file
try {
f.createNewFile();
// creates a FileWriter Object
fw = new FileWriter(f);
fw.write(max + ” Line No :”+lineNo);
fw.close();
System.out.println(“** Write data to file Successfully **”);
} catch (Exception e) {
e.printStackTrace();
}
}
}
_____________________
Output:
** Write data to file Successfully **
____________________
OutputFile:
result.txt(Save this file under D Drive.Then the path of the file pointing to it is D:\result.txt )
100 Line No :17