728x90

d-14 ) 1036번에서 한번막히긴했지만 저 코드가 왜안되는지 아직 잘이해가 가지않는다.

C에서는 분명 돌아가는거같은데 자바에서는...

1035

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Scanner;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        //
        String hexNum = sc.nextLine();
        
        //문자열 hexNum을 16진수로 바꾼다
        int num = Integer.parseInt(hexNum, 16);
        
        //int num을 8진수로 바꾼다
        String octNum = Integer.toOctalString(num);
        
        System.out.print(octNum);
        
    }
}
 
cs

 

1036

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.Scanner;
 
public class Main{
    
    public static void main(String [] args){
        
        Scanner sc = new Scanner(System.in);
        
        char word = sc.next().charAt(0);
        
        System.out.println((int)word);
        
       
        
        
    }
    
}
 
//////////////아래코드는 오답
 
 
import java.util.Scanner;
 
public class Main{
    
    public static void main(String [] args){
        
        Scanner sc = new Scanner(System.in);
        
        char s = sc.next().charAt(0);
        
        System.out.printf("%d",s);
        
       
        
        
    }
    
}}
cs

 

 

 

 

1037

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Scanner;
 
public class Main{
    
    public static void main(String [] args){
        
        Scanner sc = new Scanner(System.in);
        
        int d = sc.nextInt();
        //정수를 아스키코드로....
        
        System.out.printf("%c",d);
        //System.out.println("(char)d");
        
        
        
    }
    
}
cs

 

 

1038

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Scanner;
 
public class Main{
    
    public static void main(String [] args){
        
        Scanner sc = new Scanner(System.in);
        
        long n = sc.nextLong();
        long p = sc.nextLong();
        
        System.out.println(n+p);
        
        
        
    }
    
}
cs

 

1039

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import java.util.Scanner;
 
public class Main{
    
    public static void main(String [] args){
        
        Scanner sc = new Scanner(System.in);
        
        long n = sc.nextLong();
        long p = sc.nextLong();
        
        System.out.println(n+p);
        
        
        
    }
    
}
cs
728x90

+ Recent posts