๋ฐ์ํ
package G1_๋ฐฐ์ด์ฌํ1_ํ๊ฐ๋ฌธ์ ;
import java.util.Arrays;
public class ๋ฐฐ์ด์ฌํ1_๊ฐ์ด๋ฐ์์ํฉ_๋ฌธ์ {
/*
array[] = {123,9876,2,43,15342};
[1] ์ ๋ฐฐ์ด๊ฐ๊ฐ์ ๊ฐ์ด๋ฐ ์๋ฆฌ์ ํฉ์ ๊ตฌํ์์.
[2] ์๋ฆฌ์๊ฐ ์ง์์ธ๊ฒฝ์ฐ ์๋ค2์๋ฆฌ๋ฅผ ๋ชจ๋ ๋ํ๋ค.
[3] ๊ฐ๊ฐ์ ํฉ์ result๋ฐฐ์ด์ ์ ์ฅํ ์ถ๋ ฅ
์)
123 ==> 2
9876 ==> 8 + 7
2 ==> 2
43 ==> 4 + 3
15342 ==> 3
*/
public static void main(String[] args) {
int array[] = {123,9876,2,43,15342};
int result[] = new int[array.length];
for(int i=0; i<array.length; i++) {
int cnt = 0;
int a = array[i];
int token[] = new int[array.length];
while(a>0) {
token[cnt] = a%10;
a/=10; cnt++;
}
if(cnt%2==0) {
result[i] = token[cnt/2]+token[(cnt/2)-1];
}else {
result[i] = token[cnt/2];
}
}
System.out.println(Arrays.toString(result));
}
}
300x250
'Algorithm > Etc' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
[Java] ํฐ์ ์ธ ์ฌ์ด์ฆ๋ณ๋ก ๊ฐ์์ธ๊ธฐ - COS2๊ธ (0) | 2022.04.01 |
---|---|
[Java] 10 ์ง์๋ฅผ x ์ง์๋ก ๋ณํํ๊ธฐ (0) | 2022.03.10 |
2์ฐจ์ ๋ฐฐ์ด ์ธํ๋ฝ๊ธฐ (0) | 2022.02.03 |
(JAVA) ๋ฐฐ์ด ํฑํํ ๊ฒ์ (0) | 2022.01.24 |
์๋ฐ ๋ฐฐ์ด ๋ฌด๊ถํ๊ฝ ๋ฌธ์ (0) | 2022.01.21 |