class solution {
public void num_sepearation(int value) {
if (value >= 100) {
System.out.println("The Value has to be less than 100");
return;
}
boolean isNegative = false;
// handle negative
if (value < 0) {
isNegative = true;
}
// first modular is the 일의자리수....first base?
int ones_base = 0;
int tenth_base = 0;
if (isNegative) {
value *= -1;
ones_base = value % 10;
value /= 10;
tenth_base = value % 10;
System.out.println("1 의 자리수: " + ones_base);
System.out.println("10 의 자리수: " + tenth_base);
System.out.println("음수입니다");
} else {
ones_base = value % 10;
value /= 10;
tenth_base = value % 10;
System.out.println("1 의 자리수: " + ones_base);
System.out.println("10 의 자리수: " + tenth_base);
}
}
public static void main(String[] args) {
System.out.println("Hello");
solution sol = new solution();
int test1 = 0;
sol.num_sepearation(test1);
int test2 = -10;
sol.num_sepearation(test2);
int test3 = 100;
sol.num_sepearation(test3);
}
}
음수 일 경우...도 테스트 했다.... 독학으로써 이렇게 물어보는 문제가 너무 좋다... 와일문 필요없다... 어짜피 십의자리다.... 후....