Home 03. 기본 프로그래밍 지식
Post
Cancel

03. 기본 프로그래밍 지식

3-1. 반드시 필요한 프로그래밍 지식

  • if-else
  • for
  • 배열
1
2
3
4
5
6
7
8
9
10
11
/*
  문제 : int 형의 매개변수 a, b가 주어질 때 a+b를 리턴하세요
  class : AplusBProblem
  method : public int calc(int a, int b)
*/

public class AplusBProblem {
  public int calc(int a, int b) {
    return a + b;
  }
}

3-2. 추가적인 프로그래밍 지식

  • 정렬 : import java.util.*; Arrays.sort(array);
  • 문자열 처리 ```java String s = “abc”; //동일 판정 if(s.equals(“abc”)) System.out.println(“equals”);

//문자 하나 추출 char c = s.charAt(1); //’b’

//문자열 연결 s = “def” + s + “ghi”; //defabcghi

//문자열 자르기 s = s.substring(3,3); //”abc”

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
* 연관 배열
```java
import java.util.*;

void countStrings(String[] s) {
  Map<String, Integer> hm = new HashMap<String, Integer>();

  for(int i = 0; i < s.length; i++) {
    if(!hm.containsKey(s[i])) hm.put(s[i], 0);
    hm.put(s[i], hm.get(s[i]) + 1);
  }

  for(String key : hm.keySet() {
    System.out.println(key + " " + hm.get(key));
  }
}

*

This post is licensed under CC BY 4.0 by the author.

8장 성능 향상을 위한 인프라 구조

04. 시뮬레이션