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

Write a java program (with the main method) that reads line-by-line from a file.

ID: 3824812 • Letter: W

Question

Write a java program (with the main method) that reads line-by-line from a file. Each line in the file contains two integers separated by a space. The program then determines whether the second integer number is a multiple of the first number (i.e. If Y/X has no remainder then Y is a multiple of X). If so, it writes that pair of integers to another file called "test. out". The program continues until the end of file is reached, or any exceptional condition is encountered. Your program should show appropriate message for the following exceptional conditions and terminate appropriately. "File does not exist" will be shown when the input file is not found. "General I/O exception" will be shown when there is a problem with IO. "Invalid number format" will be shown if a line contain anything other than two integers separated by a space. It would be beneficial, if you divide the program into parts; you can complete each part separately. Complete the following private method named "processLine (String line)". This method should do the following: import java.io.*; import java.util.*;//beginning of the class ExamFillReading class ExamFileReading {private static boolean processLine (String line) throws NumberFormatException{/* split the line into two parts (separated by space) if the split results into two parts then converts the first part into an integer converts the second part into another integer if second number is a multiple of first number then return true; otherwise, return false;

Explanation / Answer

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Scanner;


public class Index {
public static void main(String[] args) {
   try
   {
   BufferedReader in;
   Scanner sc = new Scanner("hello.txt");
   System.out.println("Enter integer separated by spaces: ");
   String input = sc.nextLine();
   String[] numberString = input.split("\s+");
   for(int i = 0;i < numberString.length;i++)
   {
   int[] numbers = null;
   //assuming you have an int array numbers[]
   numbers[i] = Integer.parseInt(numberString[i]);
   if(i==0 || i%2==0)
   {
         
   }
   else
   {
       if(numbers[i]/numbers[i-1]== 0)
       {
           try{
               PrintWriter writer = new PrintWriter("Out.txt", "UTF-8");
               Scanner sct=new Scanner(System.in);
                   writer.println(numbers[i]);
                   writer.println(numbers[i-1]);
                  
               writer.close();
               } catch (IOException e) {
                   e.printStackTrace();
               }
       }
   }
   }
   }
   catch (FileNotFoundException e){
   // do stuff here..
       e.printStackTrace();
  
}
      
}
}

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