In: Computer Science
Write a Java program called Numbers that reads a file containing a list of numbers and outputs, for each number in the list, the next bigger number. For example, if the list is
78, 22, 56, 99, 12, 14, 17, 15, 1, 144, 37, 23, 47, 88, 3, 19
the output should look like the following:
78: 88
22: 23
56: 78
99: 144
12: 14
14: 15
17: 19
15: 17
1: 3
144: 2147483647
37: 47
23: 37
47: 56
88: 99
3: 12
19: 22
NOTE: If there is no bigger number in the sequence, just display the value of Integer.MAX_VALUE .
The output should be shown on the screen and also saved in a file.
Program Design
Additional Requirements
The output of your program should exactly match the sample program output given at the end
/*
* Java Program to read integers from a text file and write next largest number of integers to new file
*/
import java.io.*;
import java.util.*;
class Main {
public static int nextLargest(int list[], int val) {
int next;
next = Integer.MAX_VALUE;
for (int i = 1; i < list.length; i++) {
if (val < list[i]) {
next = list[i];
break;
}
}
return next;
}
public static void main(String[] args) throws Exception {
List<Integer> list = new ArrayList<Integer>();
File file = new File("list.txt");
FileWriter fWrite = new FileWriter("nextlist.txt");
Scanner sc = new Scanner(file);
while (sc.hasNextInt())
list.add(sc.nextInt());
int intList[] = new int[list.size()];
for (int i = 0; i < list.size(); i++) {
intList[i] = list.get(i);
}
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i) + ": " + nextLargest(intList, list.get(i)));
fWrite.write(list.get(i) + ": " + nextLargest(intList, list.get(i)) + "\n");
}
fWrite.close();
}
}

Note: Drop comments for queries.