Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

Goru

[Java] 산술연산자 본문

Java

[Java] 산술연산자

gorusair 2021. 12. 10. 22:26

사칙 연산자 + - */

class OperatorEx5 {
	public staitc void main(String[] args){
    	int  a = 10;
        int b = 4;
        
        System.out.printf("%d + %d = %d%n", a, b a + b);
        System.out.printf("%d - %d = %d%n", a, b a - b);
        System.out.printf("%d * %d = %d%n", a, b a * b);
        System.out.printf("%d / %d = %d%n", a, b a / b);
        System.out.printf("%d / %f = %f%n", a, (float)b, a / (float)b);
        
        실행결과
        10 + 4 = 14
        10 - 4 = 6
        10 * 4 = 40
        10 / 4 = 2  // 소수점 이하는 버려진다.
        10 / 4.000000 = 2.500000

 

'Java' 카테고리의 다른 글

[Java] 비교 연산자, 논리 연산자  (0) 2021.12.13
[Java] 나머지 연산자  (0) 2021.12.10
[Java] 단항연산자  (0) 2021.12.10
[Java] 산술변환  (0) 2021.12.09
[Java] 연산자(2)  (0) 2021.12.09