-
Notifications
You must be signed in to change notification settings - Fork 110
Expand file tree
/
Copy pathSimpleCalculation.java
More file actions
34 lines (28 loc) · 961 Bytes
/
Copy pathSimpleCalculation.java
File metadata and controls
34 lines (28 loc) · 961 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package simple_calculation;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Scanner;
public class SimpleCalculation {
private static int difference(long numberOfSystem){
int sum = 0;
int multi = 1;
while (numberOfSystem > 0){
long number = numberOfSystem % 10;
sum += number;
multi *= number;
numberOfSystem /= 10;
}
return multi - sum;
}
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(new FileReader("input.txt"));
long numberIn = sc.nextLong();
int numberSystem = sc.nextInt();
long numberOfSystem = Long.parseLong(Long.toString(numberIn, numberSystem));
long result = difference(numberOfSystem);
FileWriter out = new FileWriter("output.txt");
out.write(String.valueOf(result));
out.close();
}
}