1. ๋ด ํ๋ฆฐ ์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int Origin;
int a = 0;
int b = 0;
int c = 0;
int temp = 0;
Integer i = 0;
Origin = sc.nextInt();
c = Origin;
sc.close();
System.out.println(Origin);
System.out.println(c);
if(Origin < 10){
Origin *= 10;
}
while (true){
a = Origin/10;
b = Origin%10;
temp = a + b;
Origin = (b*10) + (temp%10);
i++;
if(Origin == c)
break;
}
System.out.println(i);
}
}
2. ํ๋ ธ๋ ๋ถ๋ถ
๋ฌธ์ ํด์์ ์๋ชปํ๋ค. ๋๋
์์ '10๋ณด๋ค ์๋ค๋ฉด ์์ 0์ ๋ถ์ฌ ๋์๋ฆฌ ์๋ก ๋ง๋ค๊ณ ...'๋ผ๋ ๋ถ๋ถ์ ๋ณด๊ณ
1์ด ๋ค์ด์ค๋ฉด 10, 2๊ฐ ๋ค์ด์ค๋ฉด 20์ ๋ง๋ค๋ผ๋ ์๋ฆฌ์ธ ์ค ์์๋๋ฐ, ์๊ณ ๋ณด๋ 1์ด ๋ค์ด์ค๋ฉด 01, 2๊ฐ ๋ค์ด์ค๋ฉด 02๋ก ๋ง๋ค๊ณ ๋ฌธ์ ๋ฅผ ํ์ด๋ ์๋ฆฌ์๋ค. ๋ด ์ฝ๋๋ 1์ด ์ ๋ ฅ๋๋ฉด 10์ผ๋ก ๋ง๋ค๊ณ ๋ฌธ์ ๋ฅผ ํ์๊ธฐ์ i๊ฐ์ด 60์ด ์๋ 1๋ก ๋์ค๋ ์ค๋ฅ๋ฅผ ๋ฒํ๋ค.
๋ฐ๋ผ์
if(Origin < 10){
Origin *= 10;
}
์ด ๋ถ๋ถ์ ์ง์์ผ ํ๋ค.
3. ํด๊ฒฐ์ฝ๋
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int Origin;
int a = 0;
int b = 0;
int c = 0;
int temp = 0;
Integer i = 0;
Origin = sc.nextInt();
c = Origin;
sc.close();
System.out.println(Origin);
System.out.println(c);
while (true){
a = Origin/10;
b = Origin%10;
temp = a + b;
Origin = (b*10) + (temp%10);
i++;
if(Origin == c)
break;
}
System.out.println(i);
}
}
0