더보기
에이블스쿨에서 자바로 코딩테스트를 본다고 하여 ... 자바 공부를 시작했습니다
거의 뭐 5년만에 자바를 들여다봤는데 끔찍합니다 🤢
(파이썬 사랑해 🫶🏻 파이썬 최고야 💓)
분명 전공수업에서 자바, C, C# 다 배웠는데 조금도 .. 기억이 나지 않아..... .·°՞(¯□¯)՞°·.
파이썬으로 몇줄이면 되는 문제를 자바로 수십줄 😂 하하하
그래도 어쩌겠어요 지금부터라도 친해지자 자바야 (ദ്ദി˙ᗜ˙)
입력
숫자 1개 입력
입력
3
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
숫자 2개 입력
입력
3 5
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
숫자 리스트 입력
입력
1 3 5 7 9 2 4 6 8
Scanner sc = new Scanner(System.in);
String[] input = sc.nextLine().split(" ");
int[] nums = new int[input.length];
for (int i = 0; i < input.length; i++) {
nums[i] = Integer.parseInt(input[i]);
}
문자열 2개 입력
입력
abc def
Scanner sc = new Scanner(System.in);
String a = sc.next();
String b = sc.next();
문자열 여러 줄 입력
입력
3
apple
banana
cherry
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
String[] arr = new String[n];
for (int i = 0; i < n; i++) {
arr[i] = sc.nextLine();
}
문자열+숫자 혼합 입력
입력
alpha 70
Scanner sc = new Scanner(System.in);
String s = sc.next();
int n = sc.nextInt();
숫자 붙어서 입력
입력
0101
Scanner sc = new Scanner(System.in);
char[] arr = sc.nextLine().toCharArray();
int[] nums = new int[arr.length];
for (int i = 0; i < arr.length; i++) {
nums[i] = arr[i] - '0';
}
2차원 숫자 배열 입력
입력
3
1 2 3
4 5 6
7 8 9
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
int[][] grid = new int[n][n];
for (int i = 0; i < n; i++) {
String[] line = sc.nextLine().split(" ");
for (int j = 0; j < n; j++) {
grid[i][j] = Integer.parseInt(line[j]);
}
}
2차원 문자 배열 입력
입력
3
AXBB
BXAA
XABX
Scanner sc = new Scanner(System.in);
int n = Integer.parseInt(sc.nextLine());
char[][] grid = new char[n][];
for (int i = 0; i < n; i++) {
grid[i] = sc.nextLine().toCharArray();
}
출력
기본 출력
System.out.println("Hello"); // 줄바꿈 O
System.out.print("World"); // 줄바꿈 X
System.out.printf("나이는 %d살입니다.", 10); // 서식 지정
출력
Hello
World나이는 10살입니다.
자주 쓰는 printf 서식
String name = "쫑이";
int age = 25;
double height = 175.45;
System.out.printf("이름: %s, 나이: %d, 키: %.2fcm", name, age, height);
출력
이름: 쫑이, 나이: 25, 키: 175.45cm
배열 / 리스트 출력 팁
배열 출력
int[] arr = {1, 2, 3};
for (int n : arr) {
System.out.print(n + " ");
}
System.out.println();
출력
1 2 3
리스트 출력
List<Integer> list = Arrays.asList(4, 5, 6);
for (int n : list) {
System.out.print(n + " ");
}
출력
4 5 6
'자바' 카테고리의 다른 글
프로그래머스 코딩 기초 트레이닝 🔥 조건문 / 반복문 (0) | 2025.05.01 |
---|---|
프로그래머스 코딩 기초 트레이닝 🔥 출력 / 연산 / 문자열 (0) | 2025.04.30 |
프로그래머스 코딩테스트 입문 60% (0) | 2025.04.27 |
프로그래머스 코딩테스트 입문 40% (0) | 2025.04.27 |
프로그래머스 코딩테스트 입문 20% (0) | 2025.04.25 |