U E D R , A S I H C RSS

Gu Gu Dan/재동

구구단

~cpp GugudanTestCase.java
~cpp 
import junit.framework.TestCase;

public class GugudanTestCase extends TestCase {
	public GugudanTestCase(String arg0) {
		super(arg0);
	}
	public void testCreation() {
		assertNotNull(new Gugudan());
	}
	public void testMultiply() {
		Gugudan gugudan = new Gugudan();
		assertEquals(10,gugudan.getMultiply(2,5));
		assertEquals(24,gugudan.getMultiply(4,6));
		assertEquals(81,gugudan.getMultiply(9,9));
	}
	public void test3Dan() {
		Gugudan gugudan = new Gugudan();
		int array[] = {3,6,9,12,15,18,21,24,27};
		for(int i=0;i<9;i++)
			assertEquals(array[i],gugudan.getDan(3)[i]);
	}
	public void testAllDan() {
		Gugudan gugudan = new Gugudan();
		for(int i=2;i<10;i++)
			for(int j=0;j<9;j++)
				assertEquals(i*(j+1),gugudan.getDan(i)[j]);
	}
}

~cpp Gugudan.java
~cpp 
public class Gugudan {
	public Gugudan() {
		for(int i=2;i<10;i++)
			printDan(i);
	}
	public int getMultiply(int m,int n) {
		return m*n;
	}
	public int [] getDan(int m) {
		int dan[] = new int[9];
		for(int i=0;i<9;i++)
			dan[i] = getMultiply(m,i+1);
		return dan;
	}
	public void printDan(int m) {
		for(int i=0;i<9;i++)
			System.out.println(m+"*"+(i+1)+"="+getDan(m)[i]);
		System.out.println();
	}
	public static void main(String[] args) {
		new Gugudan();
	}
}

Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2021-02-07 05:23:19
Processing time 0.0135 sec