In: Computer Science
In this project, you are required to write the java program “IO.java” to implement integer operations “+”, “−”, “*”. Specifically, your program reads operands from a file named “input.txt” (which will be manually placed under the directory of the program) as strings. Then your program converts strings to integers, and computes the addition, subtraction, and multiplication of the operands. Finally, your program creates a file named “output.txt” (under the directory of the program) and writes the results to the file. Please check the attached sample files “input.txt” and “output.txt”. In “input.txt”: 1. First line is an integer x. 2. Second line is another integer y. In “output.txt”: 1. First line is the result of x + y. 2. Second line is the result of x − y. 3. Third line is the result of x * y
If you have any doubts, please give me comment...
import java.io.*;
import java.util.Scanner;
public class IO{
public static void main(String[] args) throws FileNotFoundException {
Scanner fileScnr = new Scanner(new File("input.txt"));
int x = Integer.parseInt(fileScnr.next());
int y = Integer.parseInt(fileScnr.next());
PrintWriter pw = new PrintWriter(new File("output.txt"));
pw.println(x+y);
pw.println(x-y);
pw.println(x*y);
pw.close();
fileScnr.close();
}
}