package oop;
import java.util.Random;
/**
*
* @author Mouse
*
*/
public class test {
private static int max = 20;
private static int generation = 3;
private static int count = 5;
public static void main(String[] args) {
for (int i = 0; i < count; i++) {
int karyon = new Random().nextInt(max) + 1;
String result = new Matrix(karyon, max, generation - 1).divide();
System.out.println(result.substring(1) + "=" + karyon);
}
}
}
package oop;
public class Cell {
int karyon;
int generation;
int max;
public Cell(int karyon, int max, int generation) {
this.karyon = karyon;
this.generation = generation;
this.max = max;
}
public String Divide() {
String result = String.format("%+d", karyon);// %+d 表示 输出数据时带上正负号
if (generation > 0) {
result = new Matrix(karyon, max, generation).divide();
}
return result;
}
}
package oop;
import java.util.Random;
public class Matrix extends Cell {
public Matrix(int karyon, int max, int generation) {
super(karyon, max, generation);
}
public String divide() {
int x = new Random().nextInt(max) + 1;
StringBuilder result = new StringBuilder();
result.append(new Cell(x, max, generation - 1).Divide());
result.append(new Cell(karyon - x, max, generation - 1).Divide());
return result.toString();
}
}
转载请注明原文地址: https://ju.6miu.com/read-1000100.html