출력 예
<<누구의 구구단>>
원하는 단은?:
input => 2
2*1=2
.
.
.
.
2*9=18
계속하시겠습니까?(y/n):
원하는 단은 : 2 2 5 8 (중복 / 소팅 작업) 범위는 2 ~ 9 4개 4개 씩
2*1=2 5*1=5 8*1=8
소스 코드
import java.io.*;
class homework1
{
public static StringBuilder s_inputTemp;
public static void main(String[] args)
{
try{
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int n_NumberEnd =0;
int n_NumberStart = 0;
int n_NumberCount = 0;
String c_select="y";
System.out.println("<<성민이의 구구단>>");
do
{
System.out.print("원하는 구구단을 입력하시오 : ");
String s_input = in.readLine();
s_input.trim();
s_input = s_input.replace(" ","");
s_inputTemp = new StringBuilder(s_input);
check_other();
quicksort(0, s_inputTemp.length()-1);
for(n_NumberCount = 0; n_NumberCount <= s_inputTemp.length()/5; n_NumberCount++)
{
if(s_inputTemp.length()>4 && n_NumberCount == 0)
n_NumberEnd = 4;
else
n_NumberEnd = s_inputTemp.length() - n_NumberCount*4;
for(int i=1; i < 10;i++)
{
for(int j = 0; j<n_NumberEnd; j++)
{
System.out.print(s_inputTemp.charAt(j+n_NumberCount*4)+"*"+i+"="+(s_inputTemp.charAt(j+n_NumberCount*4)-48)*i);
System.out.print(" ");
}
System.out.println();
}
}
System.out.print("계속하시겠습니까?(Y/N)");
c_select = in.readLine();
}
while (c_select.compareTo("Y")==0 || c_select.compareTo("y")==0);
}catch(IOException e){
System.out.println("ERROR");
}
}
public static void check_other()
{
for(int i = 0; i <s_inputTemp.length();)
{
if((s_inputTemp.charAt(i)<50) || (s_inputTemp.charAt(i)>57))
{
s_inputTemp.deleteCharAt(i);
i=0;
}
else
i++;
}
}
public static void quicksort(int n_start, int n_end)
{
int n_Pivot = n_start;
int n_Left = n_start;
int n_Right = n_end;
if(n_Left >= n_Pivot && n_Pivot < n_Right && n_Left != n_Right && n_end - n_start >=1)
{
while(n_Left != n_Right)
{
if((s_inputTemp.charAt(n_Left)-48) < (s_inputTemp.charAt(n_Pivot)-48))
{
n_Left++;
}
else if(((s_inputTemp.charAt(n_Left)-48) == (s_inputTemp.charAt(n_Pivot)-48)) && (n_Left != n_Pivot))
{
s_inputTemp.deleteCharAt(n_Left);
n_Right--;
n_end--;
System.out.println("A");
}
if((s_inputTemp.charAt(n_Right)-48) > (s_inputTemp.charAt(n_Pivot)-48))
{
n_Right--;
}
else if((s_inputTemp.charAt(n_Right)-48) == (s_inputTemp.charAt(n_Pivot)-48) && (n_Right != n_Pivot))
{
s_inputTemp.deleteCharAt(n_Right);
n_Right--;
n_end--;
}
else
{
char temp = s_inputTemp.charAt(n_Pivot);
s_inputTemp.insert(n_Pivot, s_inputTemp.charAt(n_Right));
s_inputTemp.deleteCharAt(n_Pivot+1);
s_inputTemp.insert(n_Right, temp);
s_inputTemp.deleteCharAt(n_Right+1);
}
if(n_Left > n_Right)
{
int temp = n_Pivot;
n_Pivot = n_Right;
n_Right = temp;
break;
}
}
if(n_Pivot - n_start >1)
quicksort(0, n_Pivot-1);
if(n_end - n_Pivot >1)
quicksort(n_Pivot+1, n_end);
}
}
}
'Computer Science & Engineering > JAVA' 카테고리의 다른 글
2Day_homwork - pcs (0) | 2008.01.21 |
---|---|
자바 클래스 (0) | 2008.01.18 |
JavaDoc 사용 (0) | 2008.01.17 |
Java 제어문 (0) | 2008.01.17 |
헝가리안 표기법 (0) | 2008.01.17 |
댓글