코드비교

Old VersionNew Version
1import java.util.Scanner; 1import java.util.Scanner; 
2public class Main { 2public class Main { 
3public static void main(String[] args) { 3public static void main(String[] args) throws Exception {
4Scanner input = new Scanner(System.in); 4Scanner scan = new Scanner(System.in);
5int num = input.nextInt(); 5int N = scan.nextInt();
6int result =0; 6int a1, a2, a3, a4;
7while (num > 0) { 7a4 = N / 1000;
8result += num % 10; 8a3 = (N % 1000) / 100;
9num = num / 10; 9a2 = (N % 100) / 10;
10} 10a1 = N % 10;
11System.out.println(result); 11System.out.printf("%d", a1+a2+a3+a4);
12} 12} 
13} 13} 
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int num = input.nextInt();
int result =0;
while (num > 0) {
result += num % 10;
num = num / 10;
}
System.out.println(result);
}
}
import java.util.Scanner;
public class Main {
public static void main(String[] args) throws Exception {
Scanner scan = new Scanner(System.in);
int N = scan.nextInt();
int a1, a2, a3, a4;
a4 = N / 1000;
a3 = (N % 1000) / 100;
a2 = (N % 100) / 10;
a1 = N % 10;
System.out.printf("%d", a1+a2+a3+a4);
}
}