Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I have a text file with 100 random numbers. I need to create a program (using ja

ID: 3845661 • Letter: I

Question

I have a text file with 100 random numbers. I need to create a program (using java) that reads in the numbers from the file into an array. It should then find the largest number in the array and write back out a file called "result.txt". Results should contain the number that was the highest as well as the line number that it was on in the file. I have a text file with 100 random numbers. I need to create a program (using java) that reads in the numbers from the file into an array. It should then find the largest number in the array and write back out a file called "result.txt". Results should contain the number that was the highest as well as the line number that it was on in the file.

Explanation / Answer

100Rands.txt (We can See this file under D Drive.As we specified the path of the output file as D://100Rands.txt)

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: esult.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: esult.txt )

100 Line No :17

____________________

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote