자료형, 조건문, 반복문 리뷰

soomin·2023년 1월 1일

✨ to my github

Primitive type

정수형

  • short
  • int
  • long

상수형

  • double
  • float
    float f = 5.5F;

    java에서 float형 표현할때는 숫자 뒤에 'F' 입력

문자형

  • char
    문자 1개
  • boolean
  • byte
    byte는 해당문자의 ASCII code 값
    char c = 'S';
     int num = 10;
     System.out.println(c+num);
     System.out.println(c + "" + num);
     System.out.println(c + "\n" + num);

    연산자가 있을경우 ASCII 코드로 연산됨! (83+10)
    93
    S10
    S
    10


Reference type

  • String
  • 배열들
    int[] = intArray = new int[]{10, 20, 30};
     System.out.println(intArray.length); // 배열의 길이
     System.out.println(intArray[intArray.length -1]) //배열의 마지막 요소를 출력하고 싶을 땐 -1을 해줘야 함 (∵ array has index from'0')

    3
    30


Condition

  • if- else if - else
  • switch 구문
  • 삼항 연산자
    String result = (논리조건) ? (True일때 수행할 것) : (False일때 수행할 것 );

Iteration

  • for
  • for-each
    // for-each example
    String[] days = {"Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"};
    for (String day: days)
    {
      System.out.println(day);
    }
  • while
  • do-while

0개의 댓글