68 447
Assignments Done
98,6%
Successfully Done
In December 2018

Answer to Question #59008 in Java | JSP | JSF for Jian

Question #59008
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.
Expert's answer
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!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions