728x90

package ch01_variable_operator;

public class Increment01 {
    public static void main(String[] args) {
        // = 기호는 대입(assign) 연산자입니다.
        int x = 5 ; // 변수 x를 정의한 다음, 5를 대입(writer)합니다.

        //x = x + 3 ; // 누적
        x += 3 ; // 누적
        System.out.println("x : " + x);

        x *= 4 ;
        System.out.println("x : " + x);

        x %= 5 ;
        System.out.println("x : " + x);

        x -= 1 ;
        System.out.println("x : " + x);

        x += 7 ;
        System.out.println("x : " + x);

        int total = 0 ;
        total += 1 ;
        total += 2 ;
        total += 3 ;
        total += 4 ;
        total += 5 ;
        total += 6 ;
        total += 7 ;
        total += 8 ;
        total += 9 ;
        total += 10 ;
        System.out.println("total : " + total);
    }
}

 

cf ) Myjava/Increment01.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git>OperatorEx.java  (0) 2023.02.04
<Git>Operator01.java  (0) 2023.02.04
<Git>MyPrint.java  (0) 2023.02.04
<Git>MyBox.java  (0) 2023.02.04
<Git>LogicalOperator.java  (0) 2023.02.04
728x90

package ch01_variable_operator;

public class MyBox {
    public static void main(String[] args) {
        double width ;
        double height ;
        double area ;
        double perimeter ;

        width = 10.0 ;
        height = 5.0 ;

        area = width * height ;
        perimeter = 2 * (width+height) ;

        System.out.println("사각형 넓이 :" +area);
        System.out.println("사각형 둘레 :" +perimeter);
    }
}

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git> Increment01.java  (0) 2023.02.04
<Git>MyPrint.java  (0) 2023.02.04
<Git>LogicalOperator.java  (0) 2023.02.04
<Git> ErrorDebug.java  (0) 2023.02.02
<Git> Condition02.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class ErrorDebug {
    public static void main(String[] args) {
        int a,b,c ;
        a = 21 ;
        b = 7 ;
        c = a+b ;
        System.out.println("a+b = " +c);
        c = a-b ;
        System.out.println("a-b =" + c);
        c = a/b;
        System.out.println("a/b =" +c);

    }
}

 

cf) Myjava/ErrorDebug.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git>MyBox.java  (0) 2023.02.04
<Git>LogicalOperator.java  (0) 2023.02.04
<Git> Condition02.java  (0) 2023.02.02
<Git> CondOper01.java  (0) 2023.02.02
<Git> CondOper.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class Condition02 {
    public static void main(String[] args) {
        int a = 8, b = 7 ;
        int result = a >= b ? 5 : (a + 2) ;

        System.out.println("result : " + result);

        int x = 5 ;
        result = x%2 == 0 ? x+3 : x*x ;
        System.out.println("result : " + result);

    }
}

 

cf) Myjava/Condition02.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git>LogicalOperator.java  (0) 2023.02.04
<Git> ErrorDebug.java  (0) 2023.02.02
<Git> CondOper01.java  (0) 2023.02.02
<Git> CondOper.java  (0) 2023.02.02
<Git> Casting.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class CondOper01 {
    public static void main(String[] args) {

        // 최대값 변수 이름 : max

        int x = 3 ,y = 8 , z = 4 ;

        int max = x >= y ? x : y ;

        max = y >= z ? y : z ;

        max = y >= (x + z) ? y : z ;

        System.out.println("최대 수 : " + max);

    }
}

 

cf ) Myjava/CondOper01.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git> ErrorDebug.java  (0) 2023.02.02
<Git> Condition02.java  (0) 2023.02.02
<Git> CondOper.java  (0) 2023.02.02
<Git> Casting.java  (0) 2023.02.02
<Git> ArithmeticOperator2.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class CondOper {
    public static void main(String[] args) {
        int x = 3, y = 8, z = 4 ;
        int max = x > y ? x : y ;
        max = max > z ? max : z ;
        System.out.println("최대 : " + max);

        // 최소 값은 ?
        int min = x < y ? x : y ;
        min = min < z ? min : z ;
        System.out.println("최소 : " + min);

        max = x > y ? (x > z ? x : z) : (y > z ? y : z)  ;
        System.out.println("최대 : " + max);

        min = x < y ? (x < z ? x : z) : (y < z ? y : z)  ;
        System.out.println("최소 : " + min);
    }
}

 

cf) Myjava/CondOper.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git> Condition02.java  (0) 2023.02.02
<Git> CondOper01.java  (0) 2023.02.02
<Git> Casting.java  (0) 2023.02.02
<Git> ArithmeticOperator2.java  (0) 2023.02.02
<Git> ArithmeticOperator.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class Casting {
    public static void main(String[] args) {
        double d = 100 ; // 암시적 형변환
        System.out.println("d : " + d);

        // 명시적 형변환
        int i = (int)12.5 ; // (int)를 캐스트 연산자라고 함
        System.out.println("i : " + i);

        System.out.println(14/5);

        // (double)14/5 -> 14.0/5 -> 14.0/5.0 -> 2.8
        System.out.println((double)14/5);

        // (double)(14/5) -> (double)(2) -> 2.0
        System.out.println((double)(14/5));

        int kor = 50, eng = 60, math = 80 ;
        int total = kor + eng + math ;
        System.out.println("총점 : " + total);

        double average = (double)total / 3 ;
        System.out.println("평균 : " + average);

        char ch1 = 'c' ;
        char ch2 = 'a' ;
        boolean bool = ch1 > ch2 ; // 99 > 97
        System.out.println("bool : " + bool);

        int result = ch1 - ch2 + 5 ; // 99 - 97 + 5
        System.out.println("result : " + result);

        char ch3 = 'D' ;
        String str = ch3 >= 'A' && ch3 <= 'Z' ? "대문자 맞음" : "대문자 아님" ;
        System.out.println("대문자 판단 : " + str);

        char ch4 = 'e' ; // 숫자 101
        char munja = (char)(ch4 - ('a' - 'A')) ;
        System.out.println(munja);
    }
}

 

cf) Myjava/Casting.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git> CondOper01.java  (0) 2023.02.02
<Git> CondOper.java  (0) 2023.02.02
<Git> ArithmeticOperator2.java  (0) 2023.02.02
<Git> ArithmeticOperator.java  (0) 2023.02.02
<Git> Arithmetic01.java  (0) 2023.02.02
728x90

package ch01_variable_operator;

public class ArithmeticOperator2 {
    public static void main(String[] args) {
        

        int TIME = 8000 ;

        int hour ;
        int minute ;
        int second ;

        hour = TIME / 3600 ;
        minute = (TIME - hour * 3600) /60 ;

        second = TIME % 60 ;

        System.out.println("시간 : " +TIME);
        System.out.println("시 : " +hour);
        System.out.println("분 : " +minute);
        System.out.println("초 : " +second);

        System.out.println("-----------------------------");

        int x = 20 ;

        x += 5 ;

        x += 10 ;

        x -= 15 ;

        x /= 5 ;

        x *= 100 ;

        int y = 300 + x ;


        System.out.println("x 는 : " +x);

        System.out.println(+y);

    }
}

 

cf) Myjava/ArithmeticOperator2.java at master · nolooker/Myjava (github.com)

728x90
반응형

'console.log("What ? " + Cord); > Java' 카테고리의 다른 글

<Git> CondOper.java  (0) 2023.02.02
<Git> Casting.java  (0) 2023.02.02
<Git> ArithmeticOperator.java  (0) 2023.02.02
<Git> Arithmetic01.java  (0) 2023.02.02
<Git> AreaTest.java  (0) 2023.02.02

+ Recent posts

728x90
반응형
728x90
반응형