JAVA 정리 2

2021. 1. 15. 15:40·JAVA
728x90
반응형

 

Boolean can only be either true or false. Do not use double quotes.

&& = and, || = or

 

Control flow

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        if(condition) {
            //Run this code;
        } else if (condition) {
            //Run this code;
        } else {
            //Run this code;
        }
    }
}
Colored by Color Scripter
cs

 

Switch statements.

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        switch (value of contidion) {
            case value1 :
                //Run this code;
                break;
            case value2 :
                //Run this code;
                break;
            case value3 :
                //Run this code;
                break;
        }
    }
}
Colored by Color Scripter
cs

 

Default case

In switch statements, you can set a default case for when none of the cases match.

            default :
                //Run this code;
                break;
        }
cs

 

While loops

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        while (condition) {
            //Run this code;
        }
    }
}
Colored by Color Scripter
cs

 

for loops

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        for (int i=1; i<=5 ; i++) {
            //Run this code;
        }
    }
}
Colored by Color Scripter
cs

 

Using continue : continue statements skip the loop

ex ))

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        for (int i=1; i<=10 ; i++) {
            if ( i % 3 == 0) {
                continue; //skip the rest of the code in the loop
                          //if the number is divisible by 3
            }
            System.out.println(i);
        }
    }
}
Colored by Color Scripter
cs

 

Arrays [ ]

When declaring a variable for an array, you have to put [ ] after the type of each element.

ex ) int [ ] - array of integers, int [ ] numbers = { 5, 13, 29 };

String [ ] - array of strings

 

Array has a method called length, which counts the number of elements in an array.

ex ) String [ ] names = { "Jones", "Ken" };

System.out.println( names.length );   -> 2

 

Enhanced for loops

class Main {
    public static void main(String[] args) {
        System.out.println("Hello Java");
 
        for ( dataType variableName : arrayName ) {
            //Run this code;
        }
 
        ex)
        String [] names = {"John", "Ken"};
        for (String name : names) {
            System.out.println( name );
        }
    }
}
Colored by Color Scripter
cs

 

 

 

 

출처 : progate.com/dashboard

728x90
반응형
저작자표시 비영리 변경금지 (새창열림)

'JAVA' 카테고리의 다른 글

Java 정리 4  (0) 2021.01.19
Java 정리 3  (0) 2021.01.18
Java 정리 1  (0) 2021.01.14
'JAVA' 카테고리의 다른 글
  • Java 정리 4
  • Java 정리 3
  • Java 정리 1
waVwe
waVwe
    반응형
  • waVwe
    waVwe 개발 블로그
    waVwe
  • 전체
    오늘
    어제
    • ALL (184)
      • Python (1)
      • Spring (15)
      • DevOps (10)
      • Git (6)
      • JAVA (4)
      • C (22)
      • 코테 문제 풀이 (124)
        • 프로그래머스 (43)
        • 백준 (2)
        • 정올 (64)
        • SW Expert Academy (1)
        • 온코더 oncoder (14)
  • 블로그 메뉴

    • 홈
    • 방명록
  • 링크

    • 🐙 Github
  • 공지사항

  • 인기 글

  • 태그

    알고리즘
    while문
    자바
    MSA
    형변환
    progate
    아파치카프카
    정올
    스파르타코딩클럽
    java
    CI/CD
    docker
    Til
    깃헙
    C언어
    스파르타코딩
    자료구조
    연결리스트
    코테
    도커
    프로그래머스
    C
    내일배움캠프
    온코더
    깃
    스프링
    스프링부트
    springboot
    devops
    이진트리
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.0
waVwe
JAVA 정리 2
상단으로

티스토리툴바