본문 바로가기

콤퓨타/Programming) 왕초보 자바

11. (Loops and Conditions) Postfix and Prefix Expressions

한국어 명칭은: 후위연산자와 전위연산자

 

i = i + 1; 

이걸 간단한 방식으로 나타낸것이며, 

반복 작업을 수도 없이 진행하는 컴퓨터에 특화된 기능이다. 

오늘 배운것은 크게 두가지. 

1. 라인복사 단축키 

2. 연산 진행시 print 코드를 통해 출력할 때 연산이 반영되는것이 아니라 작성 하자마자 그 다음부터 바로 반영된다. 

 

라인 복사 단축키: ctrl + option + 아래커서 누르면 바로바로 복사가 된다. 

public class App {
	
	public static void main(String[] args) {
		
		int otters = 5; 
		int giraffes = 10; 
		int elephants = 3; 

		System.out.printf("Otters: %d \n", otters);
		// ctrl option down arrow 하면 복사 !! 대박스 
		System.out.printf("Giraffes: %d \n", giraffes);
		System.out.printf("Elephtants: %d \n", elephants);
		
		
	}
}

 

같은 코드를 반복해서 작성해야 할 때 

특히 sysout 하고 ctrl + space bar 누르면 바로 만들어지는 println 대신 printf를 넣어야 할 때나, 뭐 아직 모르는 코드를 복붙해야 하는 상황에서 유용하다. ... 초보니까 직접 쳐서 손가락에 익히는것이 사실 금상 첨화겠으나... ^^ 이렇게 꼼수부리는 단축키에서도 기쁨을 얻어야지 이 공부가 계속 진행될 수 있을 것 같다.... ㅋㅋ

 

public class App {
	
	public static void main(String[] args) {
		
		int otters = 5; 
		int giraffes = 10; 
		int elephants = 3; 
		
		int animals = otters++ + otters; 
		//11 = 5+6 , otters가 후위이므로 후위 연산자 다음의 otters에 이미 +1이 반영되었음 
		
		int animals2= --elephants + ++otters + giraffes++ + elephants + giraffes; 
		//2+7+ 10 + 2 + 11  , 이미 전 라인에서 otters ++ 반영된 상태에서 전위연산 반영 하므로 7, 마지막 giraffes도 앞선 giraffes의 후위연산 반영 받아 11
		
		//otters++ ; 
		
		System.out.printf("Otters: %d \n", otters);
		// ctrl option down arrow 하면 복사 !! 대박스 
		System.out.printf("Giraffes: %d \n", giraffes);
		System.out.printf("Elephtants: %d \n", elephants);
		//System.out.printf("total number of the animals: %d \n" , otters + giraffes + elephants);
		System.out.printf("Animals: %d \n", animals);
		System.out.printf("Animals: %d \n", animals2);
		
	}
}

 

 

출력값

 

 

선생님이 헷갈릴 수 있는 파트라며 친히 숫자까지 한 땀 한 땀 작성해가며 설명해주시는데. 초보를 대하는 정성이 느껴진다. 

또한, 컴퓨터라는것이 꽤나 실시간으로 움직인다는 사실을 깨닫기 시작할대마다 놀라움. 

 

이렇게라도 배울거리 착즙할 수 있는 초보는 기쁨미다... ^^ 오늘도 해피코딩