본문 바로가기

혼공

week1-java

기본미션 - JDK 설치 화면 인증하기

 

 

 

 

 

chapter 01-chapter 05

 

 

자료형

int     n = 1;     // 정수   byte short int long(L)
double  d = 1.0;   // 실수   float(f) double
char    c = 'a';   // 문자   char
String  s = "hi";  // 문자열 String
boolean b = false; // 불     boolean

System.out.printf("%d %f %c %s %b \n", n, d, c, s, b);
System.out.println(n);
System.out.print(n);

형변환

d = 1 + 1.0;   // 작은숫자 + 큰숫자
s = 1 + "2";   // 숫자     + 문자열

d = n;         // 작은숫자 -> 큰숫자
n = (int) d;   // 큰숫자 -> 작은숫자

s = String.valueOf(n);     // 숫자 -> 문자열
n = Integer.parseInt(s);   // 문자열 -> 숫자

조건문

Random random = new Random();
int age = random.nextInt(20) + 1;

if (age < 18) n = 0;
else          n = 1;

n = (age < 18) ? 0 : 1;

switch (age / 9) {
    case 0:
    case 1:
        n = 0;
        break;
    default:
        n = 1;
}

반복문

int[] arr = {10, 20};

for (int x : arr) 
    System.out.println(x);

배열

// 자바에서 배열과 클래스는 참조타입이다 (heap)

int[] ar = new int[2];
int[] a2 = {10, 20};

Arrays.sort(ar);       // 배열 정렬
Arrays.toString(ar);   // 배열 출력

 

 

 

'혼공' 카테고리의 다른 글

week2-python  (0) 2023.07.16
week2-java  (0) 2023.07.15
week2-javascript  (0) 2023.07.13
week1-python  (0) 2023.07.09
week1-javascript  (0) 2023.07.03