Records rather than Memories

연산자 본문

Software/JAVA

연산자

Downer 2019. 10. 2. 17:00
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package javatutorials.operator;
 
public class Number {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
        System.out.println(6 + 2);
        System.out.println(6 - 2);
        System.out.println(6 * 2);
        System.out.println(6 / 2);
        
        System.out.println(Math.PI); //수학관련 캐비넷 3.141592..
        System.out.println(Math.floor(Math.PI)); //floor는 내림 3.14가 3이 된다
        System.out.println(Math.ceil(Math.PI)); // 4.0
    }
 
}
 
cs

기본 연산자와 Math 사용한 간단한 main

+ , -, *, /, %

 

 

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
package javatutorials.operator;
 
public class ConcatDemo {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
        String firstString = "This is";
        String secondString = " a concatenated string";
        String thirdString = firstString + secondString;
        System.out.println(thirdString);
        //문자와 문자의 결합에 + 사용
    }
 
}
 
cs

String에서 + 는 문자와 문자의 결합이다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
package javatutorials.operator;
 
public class ConcatDemo {
 
    public static void main(String[] args) {
        // TODO Auto-generated method stub
 
    int a = 10;
    int b = 3;
    
    float c = 10.0F;
    float d = 3.0F;
    
    System.out.println(a/b); //3.3333 소수점은 버리게 된다.
    System.out.println(c/d); //소수점 이하 값을 잃어버리지 않는다.
    System.out.println(a/d); //a를 float로 형변환 후 계산
    
    }
 
}
 
cs

출력되는 값
3

3.3333333

3.3333333

 

 

 

 

 

'Software > JAVA' 카테고리의 다른 글

비교와 Boolean  (0) 2019.10.14
[java] 단항 연산자 & 연산의 우선순위  (0) 2019.10.02
명시적 형 변환  (0) 2019.10.02
암시적 형 변환  (0) 2019.10.02
[java] Data type  (0) 2019.10.01
Comments