My footsteps

비트연산자 / 복합 대입 연산자 / 연산자 우선순위 / 제어구조 본문

국비수업/수업정리

비트연산자 / 복합 대입 연산자 / 연산자 우선순위 / 제어구조

밀김 2023. 2. 20. 10:15
728x90

 

 

 

 

 

 

 

 

- data=(byte) (data<<2); 데이터를 왼쪽으로 두칸 밀어서 byte에 담았다는 의미

 

https://youtu.be/aEYDTshCF7M

 

 

 

http://www.tcpschool.com/c/c_operator_bitwise

 

코딩교육 티씨피스쿨

4차산업혁명, 코딩교육, 소프트웨어교육, 코딩기초, SW코딩, 기초코딩부터 자바 파이썬 등

tcpschool.com

 

 

		byte data = 94; //[0101 11]10
		int size = data >> 2; //size값 : 00[01 0111]
		int type = data ^ size << 2; //type값: 0000 0010 , ^:차집합 이라는뜻
		
		System.out.printf("size : %d, type : %d\n",size,type);

 

 

 

 

 


 

 

 

 

 

 

- 3항 연산자 value3 = (3<1) ? value1 : value2 (참과 거짓을 따지는것 참이면 1에 저장 거짓이면 2에 저장 뭐 이런..식..)

 

 


 

 

 

- 산술연산자(+ - * /) > 비교연산자(<= >=) > 관계연산자(부등호) > 대입연산자(= ==)

* (소괄호()가 연산순위중 최고!) * 

 

 

 


 

 

 

- 언어의 필수요소 4가지 : 데이터 연산자 제어구조(제어문) 배열

 

 

 


 

 

- 제어구조 : 흐름을 제어하는것

 

- 컴퓨터 프로그램은 반복을 기본으로 한다

 

- 제어구조의 종류 : 선택문(if else else if) / 반복문(while do-while for) / 분기문(switch case) 

 

 

 

 

 

- while : 조건이 만족하는 한! 무한으로 계속 진행

 

 

 

package ex3.control;
public class Program {
	public static void main(String[] args) {
		
		int x = 3;
		
		// x가 5보다 작을때만 출력하게 해줘 x<5
		while(x<5) {
			System.out.println(x);
			x++;
		}
		System.out.println("작업완");
		
	}
} //3 4 작업완 출력

 

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 3;
		
		while(true) {
			System.out.println("haha");
			
			if(x==3)
				break;
		}
		
	}
}

 

 

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 3;
		
		while(x<15) {
			System.out.println("haha");
			
			x+=2; //x=x+2 → 3(x<15) 5 7 9 11 13이 출력..
				
		}
		
		System.out.println("작업완");
		
	}
}

 

 

이렇게 (조건식)반복횟수에 변수를 넣을수도 있다.

★이 패턴 외우기!!★

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 0;
		int count = 6;

		while(x<count) {
			System.out.println("haha");			
			x++;				
		}	
		System.out.println("작업완");
		
	}
}

 

 

 

- 흐름을 제어할때 가장 중요한것, 반복을 제어하는것

 

- 변수를 0으로 설정한뒤에, 그 변수를 조건식에 넣으면 보기도 간결하고 편하다

 

 

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 0;
	
		while(x<20) {
			
			if(x==5 || x==10) //x가 5일때와 10일때 별이 출력되게 
			System.out.print("☆");
			
			x++;
				
		}
		
		System.out.println();
		System.out.println("작업완료");
		
	}
}

 

 

else문(예외)을 이용하여 세번째 별만 까맣게 하기 

(else문은 괄호를 넣지 않는다)

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 0;
		

		while(x<20) {
			
			if(x==2) 
				System.out.print("★");
			else
				System.out.print("☆");
			
			x++;

		}
		
		System.out.println();
		System.out.println("작업완료");
		
	}
}

 

 

else if 문을 이용하여 예외 추가하기 

(if > else if > else 이순서로 정렬해야한다)

package ex3.control;
public class Program {
	public static void main(String[] args) {

		int x = 0;
		

		while(x<20) {
			
			if(x==5) 
				System.out.print("★");
			else if(x==6)
				System.out.print("@");
			else
				System.out.print("☆");
			
			x++;

		}
		
		System.out.println();
		System.out.println("작업완료");
		
	}
}

 

 

- if 밑에 else가 나오면 자동으로 if-else문으로 인식된다 짝이 자동으로 맞춰짐

 

 

 

 

 

 

728x90

'국비수업 > 수업정리' 카테고리의 다른 글

switch문  (0) 2023.02.22
반복문 복습 / for, while, switch문  (0) 2023.02.21
콘솔 입력 / 연산자  (0) 2023.02.17
시맨틱 태그 / 형식 지정자 / 주석 keyword  (0) 2023.02.16
문자열 / 형식지정자 / 콘솔 입력  (0) 2023.02.16