1
0
Fork 0
StringMultiplication/src/de/janchristiangruenhage/demo/math/multiplication/Main.java
Jan Christian Grünhage a58c7aa269 Bugfixes
Bug where factors where twice as long as ecpected fixed
Optimizations

HELP FROM CS CLASS
2016-01-14 12:40:43 +01:00

41 lines
1.4 KiB
Java

package de.janchristiangruenhage.demo.math.multiplication;
import de.janchristiangruenhage.math.multiplication.LongMultiplication;
import de.janchristiangruenhage.util.MultiOutput;
import java.io.FileNotFoundException;
import java.io.PrintWriter;
public class Main {
public static void main(String[] args) {
String factorOne = "";
//Constructs the factorOne string
for (int i = 0; i < 20; i++) {
factorOne += (char) (48 + ((int) (Math.random() * 10)));
//adds a random number character to the factorOne string
}
String factorTwo = "";
//Constructs the factorTwo string
for (int i = 0; i < 5; i++) {
factorTwo += (char) (48 + ((int) (Math.random() * 10)));
//adds a random number character to the factorTwo string
}
MultiOutput output = getOutputs(factorOne, factorTwo);
//gets the output for these factors;
output.println(new LongMultiplication(factorOne, factorTwo, 50, 0).printCalculation());
//prints the calculation
}
private static MultiOutput getOutputs(String factorOne, String factorTwo) {
MultiOutput output = new MultiOutput();
output.add(System.out);
try {
output.add(new PrintWriter(("Multiplication" + factorOne.hashCode() + factorTwo.hashCode())));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
return output;
}
}