Input
The input consists of several test cases. In each line of input, there are two integers 1 ≤ M ≤ 300, the
number of rows in the chocolate and 1 ≤ N ≤ 300, the number of columns in the chocolate. The input
should be processed until end of file is encountered.
Output
For each line of input, your program should produce one line of output containing an integer indicating
the minimum number of cuts needed to split the entire chocolate into unit size pieces.
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws FileNotFoundException {
File myFile = new File("file.txt");
Scanner sc = new Scanner(myFile);
while(sc.hasNext()){
int M = sc.nextInt();
int N = sc.nextInt();
System.out.println(M + N - 2);
}
}
}
Need a fast expert's response?
Submit order
and get a quick answer at the best price
for any assignment or question with DETAILED EXPLANATIONS!
Learn more about our help with Assignments:
JavaJSPJSF