public static void main(String[] args) {
boolean Kor=false;
boolean Adult=true;
System.out.println(Kor && Adult); // ANd -> &&는 둘다 T일 때만, T
System.out.println(Kor || Adult); // OR -> ||는 하나라도 T이면, T
System.out.println(1==0 && 1/0==0); // &&는 앞에 있는 피연산자가 F이면 뒤를 평가하지 않음(단축평가)
System.out.println(1!=0 || 1/0==0); // ||은 앞에 있는 피연산자가 T이면 뒤를 평가하지 않음
String str1 = new String("java");
String str2 = new String("java");
System.out.println(str1==str2); // String 안에 텍스트가 저장 되어 있는게 아니라 텍스트 데이터가 있는 주소가 저장되어있음
Scanner sc = new Scanner(System.in);
String t1 =sc.nextLine();
String t2 =sc.nextLine();
System.out.println(t1==t2); // 다르다고 인식, scanner가 각기 다른 별개의 텍스트로 메모리에 저장, 즉 주소비교
System.out.println(t1.equals(t2)); // 텍스트가 같은지 비교 (내용이 같은지)
char c ='A'; // 원시타입 -> 메모리에 직접저장
System.out.println('A'=='A'); //한글자씩 직접적으로 메모리 저장되는 char는 비교가 보장된다.
}
2. 증감 연산자(전위, 후위)
int b =10;
System.out.println(b); //10
System.out.println(b++); //10
System.out.println(b); //11
int c = b++;
System.out.println(b +""+c); // 12 11
int d = ++b;
System.out.println(b+""+d); // 13 13
- 파이썬은 증감 연산자가 없음
3. if문(조건)
public class Solution03 {
public static void main(String[] args) {
int c = 100;
if (c < 40) {
System.out.println("c가 40보다 작다");
} else if (c<90) {
System.out.println("c가 90보다 작다");
} else {
System.out.println("아무 조건도 해당하지 않는다.");
}
}
4. switch문(조건)
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int day = sc.nextInt();
switch (day%7) {
case 0:
System.out.println("sun");
break;
case 1:
System.out.println("mon");
break;
case 2:
System.out.println("tue");
break;
case 3:
System.out.println("wen");
break;
default:
System.out.println("해당 없음");
break;
}
}
5. for문(반복)
public static void main(String[] args) {
for(int i =0; i<5; i+=2) {
System.out.println(i);
}
-------------------------------------------------------
for (int a=5; a>=0; a--) {
System.out.println(a); // '5-a' 으로도 표현 가능
}
}
6. while문(반복)
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
String name ="";
while(name.equals("")) {
Systehttp://m.out.print("name: ");
name=sc.nextLine();
if(name.equals("")) {
System.out.println("nothing");
} else {
System.out.println("hi "+name);
}
}
----------------------------------------------------------------
int i=0;
while(i<5) {
System.out.println(i);
i++;
}
----------------------------------------------------------------
int j =0;
do {
System.out.println(j);
j++;
} while (j<5);
}