본문 바로가기

JAVA

(227)
주석 주석이란 일종의 설명글을 의미한다. 코드파일에 우리가 코드를 적으면 해당 컴파일 단계에서 해당코드는 JVM에서 실행할 명령어로 등록이 되는데 주석의 경우 컴파일 단계에서 명령어 등록을 할 때 무시가 되어서 실제 코드가 아닌 걸로 분류된다. 교과서 등의 일반적인 텍스트와 마찬가지로 주석은 우리가 어떤 코드에 대한 설명 혹은 작성 의도를 적을 때 사용된다. 또한, 주석은 실제 코드가 아니므로 문법을 안지켜도 전혀 문제가 되지 않는다. 주석에는 한 줄 주석과 여러줄 주석이 있다. - 한줄 주석: //로 시작하고 엔터를 치기 전까지의 모든 글자가 주석이다. - 여러줄 주석 : /*로 시작하고 */가 나오기 전까지는 모든 줄이 주석이 된다. public class Ex01Comment { public static..
논리연산자(NOT) package org.opentutorials.javatutorials.eclips; public class NotDemo { public static void main(String[] args) { if (!true) { System.out.println(1); } if (!false) { System.out.println(2); } } } !는 부정의 의미로 not이라고 읽는다. Boolean의 값을 역전시키는 역할을 한다. true에 !를 붙으면 false가 되고 false에 !을 붙이면 true가 된다.
논리연산자(OR) package org.opentutorials.javatutorials.eclips; public class OrDemo { public static void main(String[] args) { if (true || true) { System.out.println(1); } if (true || false) { System.out.println(2); } if (false || true) { System.out.println(3); } if (false || false) { System.out.println(4); } } } package org.opentutorials.javatutorials.eclips; public class LoginDemo4 { public static void main(S..
논리연산자 논리연산자란 AND(논리곱), NOT(논리부정)을 표현하는 연산자이다. && AND 이항연산자 좌항과 우항의 값이 둘다 참일때 참 A && B [A와 B가 참일때 참] || OR 이항연산자 좌항과 우항의 값이 둘 중 하나라도 참이면 참 A || B [A가 참이거나 B가 참일때 참] ! NOT 단항연산자 좌항과 우항의 값이 참이면 거짓, 거짓이면 참 !A [A가 참이면 거짓반환] [A가 거짓이면 참반환] if (true && true) { System.out.println(1); } if (true && false) { System.out.println(2); } if (false && true) { System.out.println(3); } if (false && false) { System.out.p..
조건문(switch) 조건문의 대표적인 문법은 if문이다. 사용빈도는 적지만 조건이 많다면 switch문이 로직을 보다 명료하게 보여줄 수 있다. package org.opentutorials.javatutorials.eclips; public class SwitchDemo { public static void main(String[] args) { System.out.println("switch(1)"); switch(1) { case 1: System.out.println("one"); case 2: System.out.println("two"); case 3: System.out.println("three"); } System.out.println("switch(2)"); switch(2) { case 1: System..
조건문(중첩)
조건문(응용) package org.opentutorials.javatutorials.condition; public class LoginDemo { public static void main(String[] args) { String id = args[0]; if(id.equals("egoing")){ System.out.println("right"); } else { System.out.println("wrong"); } } } args[](입력값) -> Run configurations(이프로그램을 실행할때 설정을 바꿀 수 있음) -> Arguments(입력값)
조건문(else) if 만으로는 좀 더 복잡한 내용을 처리하는데 부족하다. if-else절은 if 절의 값이 true일 때 then절이 실행되고, false일 때 else절이 실행된다. if (false) { System.out.println(1); } else { System.out.println(2); } } } package org.opentutorials.javatutorials.condition; public class Condition3Demo { public static void main(String[] args) { if (true) { System.out.println(1); } else { System.out.println(2); } } } < if(fa..