티스토리 뷰

JAVA 160530-2

package pack;


public class test2 {


public static void main(String[] args) {

// 연산자

int a = 5; // 치환 연산자

int b = 3;

int c = a + b;

System.out.println(a + b);

System.out.println(a - b);

System.out.println(a * b);

System.out.println(a / b); //몫

System.out.println(a % b); //나머지

System.out.println(a / (double)b); //몫2

//\\\\\\\\\\\\\\\\\\\\\\참고\\\\\\\\\\\\\\\\\\\\\\\\\

System.out.println(a / 0.0); // Infinity 무한대

System.out.println(a % 0.0); // NaN 그딴거 없음.

System.out.println(3 + 4 * 5); // 곱하기 나누기가 더하기 빼기보다 우선순위가 높다.

System.out.println((3 + 4) * 5); // ()는 최우선순위

String ss1 = "대한";

String ss2 = "민국";

String ss3 = ss1 + ss2; //문자열 더하기

System.out.println(ss3);

System.out.println(ss3 + " " + 82); //숫자는 문자화

System.out.println(ss3 + " " + (80 + 2)); //가로쳐주니 숫자로 인식하네?

String ss4 = "5" + 6;

System.out.println(ss4);

int ia = Integer.parseInt("5") + 6 + 1; //문자인 숫자를 숫자로 바꿔줌. 하나를 바꾸면 숫자열 더하기로 바뀜.

System.out.println(ia);

String ss5 = Integer.toString(5) + 6 + 1; //숫자를 문자로 바꿔줌. 하나를 바꾸면 문자열 더하기로 바뀜.

System.out.println(ss5);


//누적

int no = 1;

System.out.println(no);

System.out.println(no = no + 1);

System.out.println(no = no + 1);

System.out.println(no = no + 1);   // 값은 4, 숫자가 누적된다.

no += 1;

System.out.println(no); //5

no++; //증감연산자 --

System.out.println(no); //6

++no;

System.out.println(no); //7

System.out.println();

//증감 연산자에 관하여\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

int imsi = 5;

int result = ++imsi + 1;

System.out.println(imsi);

System.out.println(result);

System.out.println();

int imsi2 = 5;

int result2 = imsi2++ + 1;

System.out.println(imsi2);

System.out.println(result2);

//\\\\\\\\\\\\요따구로 하면 헷갈려서 잘 쓰지 않는다.\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//부호에 관하여

System.out.println();

int imsi3 = 3;

System.out.println(imsi3); //값 3

System.out.println(-imsi3); //값 -3

System.out.println(imsi3 * -1); //값 -3

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

}


}



'📁 공부정리 > JAVA' 카테고리의 다른 글

JAVA 160531-4 정수 값 처리  (0) 2016.05.31
JAVA 160531-3 입력받기  (0) 2016.05.31
JAVA 160531-2 연산처리  (0) 2016.05.31
JAVA 160531-1 (연산 정리)  (0) 2016.05.31
JAVA 160530-1  (0) 2016.05.30

Recent Comments