코드업 기초 100제 (25번 까지) 문법들
Algorithm/풀었던문제 2019. 11. 12. 16:01- " "출력 해보기 -
/옆에 ""를 쓰면 ""를 출력 할 수 있다.
1 2 3 4 5 6 7 8 9 | public class Main { public static void main(String[] str) { System.out.println("\"!@#$%^&*()\""); } } | cs |
- \출력 해보기 -
\를 연속으로 두번사용하면 \를 출력 할 수 있다.
1 2 3 4 5 6 7 8 9 | public class Main { public static void main(String[] str) { System.out.println("\"C:\\Download\\hello.cpp\""); } } | cs |
- 아스키 코드를 사용한 기호 출력 -
아래와 같은 형식의 아스키 코드를 사용하면 기호 출력 가능
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | public class Main { public static void main(String[] str) { System.out.println("\u250C\u252C\u2510"); System.out.println("\u251C\u253C\u2524"); System.out.println("\u2514\u2534\u2518"); } } | cs |
- 입력받은 숫자를 그대로 출력 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | import java.util.Scanner; public class Main { public static void main(String[] str) { Scanner scn = new Scanner(System.in); int a = scn.nextInt(); System.out.println(a); } } | cs |
- 입력받은 문자를 그대로 출력 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | import java.util.Scanner; public class Main { public static void main(String[] str) { Scanner scn = new Scanner(System.in); String a = scn.nextLine(); System.out.println(a); } } | cs |
- 입력받은 소수를 출력 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.util.Scanner; public class Main { public static void main(String[] str) { Scanner scn = new Scanner(System.in); float a = scn.nextFloat(); System.out.format("%f", a); } } | cs |
- c언어에서 처럼 %d를 써서 여러개의 숫자를 출력할 때 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import java.util.Scanner; public class Main { public static void main(String[] str) { Scanner scn = new Scanner(System.in); int a = scn.nextInt(); System.out.println(String.format("%d %d %d",a,a,a)); } } | cs |
- 시간을 입력받아서 출력하기 -
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | import java.util.Scanner; public class Main { public static void main(String[] str) { String a; Scanner sc = new Scanner(System.in); a = sc.nextLine(); sc.close(); //문자열로 받고, ":"를 기준으로 잘라서 사용한다는 뜻이다. String[] time = a.split(":"); System.out.format("%d:%d", Integer.parseInt(time[0]),Integer.parseInt(time[1])); } } | cs |
'Algorithm > 풀었던문제' 카테고리의 다른 글
알고리즘 기초 - 4 (10진수를 2진수로 변환) (0) | 2019.12.04 |
---|---|
알고리즘 기초 - 3 (최빈수 출력) (0) | 2019.12.03 |
알고리즘 기초 - 2 (파보나치 수열 출력) (0) | 2019.12.03 |
알고리즘 기초 - 1 (학생이름 저장 및 검색) (0) | 2019.11.30 |
코드업 기초 100제 (40번 까지) 문법들 (0) | 2019.11.25 |