JAVA/코딩 테스트

[JAVA] CodeUp 기초 1012 ~ 1015

jinnkim 2022. 2. 8. 23:33

 

 

 

CodeUp

☆ 파이썬 다운로드 : 파이썬3 ☆ 무료 C언어 IDE : Code::blocks       DEV C++ ☆ 추천 온라인 IDE : C   C++11   Python3   Java ☆ 채점 가능 언어 : C, C++, JAVA, Python 3.5 ★ C++로 제출시 void main()을 사용하면

codeup.kr

 


 

1012번 문제

- 실수 1개 입력받아 그대로 출력하기

 

 

코드

 

1
2
3
4
5
6
7
8
9
10
11
12
public class Main2 {
    public static void main(String[] args) {
        
        //1012
        Scanner sc = new Scanner(System.in);
        float a = sc.nextFloat();
        System.out.print(a); 
        sc.close();
    }
 
}
 
cs

 

 

출력 내용(Console 결과)

 

 


 

1013번 문제

- 정수 2개 입력받아 그대로 출력하기

 

 

코드

 

1
2
3
4
5
6
7
8
9
10
11
12
public class Main3 {
    public static void main(String[] args) {
        //1013
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        
        System.out.print(a+" "+b);
        sc.close();
        }
}
 
cs

 

 

출력 내용(Console 결과)

 

 


 

1014번 문제

- 문자 2개 입력받아 순서 바꿔 출력하기

 

 

 

코드

 

1
2
3
4
5
6
7
8
9
10
11
public class Main3 {
    public static void main(String[] args) {
        //1014
        Scanner sc = new Scanner(System.in);                
        String a = sc.next();
        String b = sc.next();
                
        System.out.print(b+" "+a);
        sc.close();        }
}
 
cs

 

 

출력 내용(Console 결과)

 


 

1015번 문제

- 실수 입력받아 둘째 자리까지 출력하기

 

 

 

코드

 

1
2
3
4
5
6
7
8
9
10
public class Main3 {
    public static void main(String[] args) {
        //1015
        Scanner sc = new Scanner(System.in);                
        float c = sc.nextFloat();
        System.out.printf("%.2f",c); 
        sc.close();
        }
}
 
cs

 

 

 

출력 내용(Console 결과)

 

 

 

< 공부하기 >

1. nextFloat()

   - 실수형 입력 받음

2. 소수점 출력하기  - "%._f"

  - _입력 받을 자리 작성