알파카징징이 알파카징징이 코딩하는 알파카

java 입문 수업(생활코딩)_30_연산자 (1/4)

» writing

java 입문 수업(생활코딩) 수업을 참고하여 작성하였습니다

JAVA_연산자 (1/4)

정의


연산자 (1/4)

1. 연산자(operator)
  : 특정한 작업을 하기 위해서 사용하는 기호를 의미

  1) 산술 연산자
    : 수학적인 계산에 사용되는 연산자
  + 더하기
  -	빼기
  *	곱하기
  /	나누기
  %	나머지
package org.opentutorials.javatutorials.operator;
 
public class ArithmeticDemo  {
    public static void main(String[] args) {
        // result 의 값은 3
        int result = 1 + 2;
        System.out.println(result);
  
        // result 의 값은 2
        result = result - 1;
        System.out.println(result);
  
        // result 의 값은 4
        result = result * 2;
        System.out.println(result);
  
        // result 의 값은 2
        result = result / 2;
        System.out.println(result);
  
        // result 의 값은 10
        result = result + 8;
        // result 의 값은 3
        result = result % 7;
        System.out.println(result);
    }
}
// 3
// 2
// 4
// 2
// 3
package org.opentutorials.javatutorials.operator;
 
public class RemainerDemo {
    public static void main(String[] args) {
        int a = 3;
        System.out.println(0%a);
        System.out.println(1%a);
        System.out.println(2%a);
        System.out.println(3%a);
        System.out.println(4%a);
        System.out.println(5%a);
        System.out.println(6%a);
    }
}

//1
//2
//0
//1
//2
//0
  1) 산술 연산자
    : 수학적인 계산에 사용되는 연산자
    : 연산자는 숫자와 숫자를 더할 때 사용되지만, 
    문자열과 문자열을 결합할 때도 사용
package org.opentutorials.javatutorials.operator;
 
class ConcatDemo {
    public static void main(String[] args){
        String firstString = "This is";
        String secondString = " a concatenated string.";
        String thirdString = firstString+secondString;
        System.out.println(thirdString);
    }
}

// This is a concatenated string.