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

Please help!! Write a program that merges integers from two input files and stor

ID: 3622843 • Letter: P

Question


Please help!!

Write a program that merges integers from two input files and stores result into a third file in sorted order from the smallest to largest. The output file should be read within your program to verify the contents. Assume the input files are in sorted order in ascending order. Use comments and label your output.

Execute the program twice:
• A successful execution
• An unsuccessful execution where the open of one of the input files fails. Display a message and exit the program.

First input file:
3 5 7 9 10

Second input file:
2 7 8 12 15 17

Explanation / Answer

please rate - thanks

import java.util.*;
import java.io.*;
public class mergefile
{public static void main(String[] args)throws FileNotFoundException
{int count=0,i;
Scanner in=new Scanner(new File("input.txt"));
Scanner in1=new Scanner(new File("input1.txt"));
if(in==null||in1==null)
     System.out.println("an input file didn't open program aborting");
else
{PrintStream out=new PrintStream(new File("output.txt"));
boolean> int n,m;
n=in.nextInt();
m=in1.nextInt();
while(one&&two)
    {
    if(n<m)
        {out.println(n);
         if(in.hasNextInt())
                n=in.nextInt();
            else
           >          }
     else
        {out.println(m);
           if(in1.hasNextInt())
                m=in1.nextInt();
            else
            two=false;
        }
     }
if(two)
{ out.println(m);
     while(in1.hasNextInt())
       {m=in1.nextInt();
        out.println(m);
        }
   }
else
   { out.println(n);
    while(in.hasNextInt())
       {n=in.nextInt();
        out.println(n);
        }
}
out.close();
in.close();
in1.close();
in=new Scanner(new File("output.txt"));
System.out.println("The data in the output file is");
while(in.hasNextInt())
    System.out.println(in.nextInt());
in.close();
}
}     
}