728x90
SMALL
int형은 %d
p | r | o | g | r | a | m | m | i | n | g |
문자열은 %c
첫번째 포문 중요
www.pythontutor.com/visualize.html#mode=edit
순서대로 나와서 쉽게 볼 수 있는 곳
if (k>j) {
result = k++;//아래와 같음
result = k;
k = k + 1;
}else {
result = --L;//아래와 같음
L = L -1;
result = L;
k++은 저장먼저 하고 1증가
--L은 감소시키고 증가
result = j<k? k++ : --L;
맞으면 k++ 틀리면 --L
public class Main {
public static void main(String[] args) {
int i, j =0;
for (i = 0; i < 8; i++) {
j += i;
}
System.out.printf("%d, %d\n", i, j);
}
}
결과값 8, 28
public class Main {
public static void main(String[] args) {
int i=0, hap = 0;
do {
++i;
hap += i;
} while (i<5);
System.out.printf("%d, %d\n", i, hap);
}
}
i=4, hap =10인줄알았는데
4가 5보다는 작으니까 한번 더 실행되서 5, 15됨
^: 모두 같으면 0, 서로다르면 1
&: 두 비트가 모두 1일때만 1
| : 두 비트 중 한 비트라도 1이면, 1
a 14 = 0000 1110
b 19 = 0001 0011
~a = 1111 0001 = -15 (왜?) 나는 241 나오는데... 아 +1을 해주고 앞에 수를 마이너스를 해주면 된다고한다!
a^b = 0001 1101 : 29
a&b = 0000 0010 : 2
a|b = 0001 1111 : 31
class IntClass{
int a;
int b;
int c;
}
public class Main {
public static void main(String[] args) {
IntClass myVar = new IntClass();
myVar.a = 10;
myVar.b = 20;
prnt(myVar);
System.out.printf("a=%d, b=%d, c=%d\n", myVar.a, myVar.b, myVar.c);
}
static void prnt(IntClass myVar) {
myVar.a += 30;
myVar.b -= 30;
if (myVar.a <= myVar.b) {
myVar.c = myVar.a + myVar.b;
}else {
myVar.c = myVar.a - myVar.b;
}
}
}
출력결과 a=40, b=-10, c=50
public class Main3 {
public static void main(String[] args) {
int a = 035, b = 0x35, c = 35;
System.out.printf("%d\n", a);
System.out.printf("%d\n", b);
System.out.printf("%d\n", c);
}
}
앞에 0이 붙으면 8진수 Dec
0x가 붙으면 16진수
아무것도 안붙으면 10진수
계산기 없음 못하겠네
아니안해 ㅋ
++a 증가시켜서 출력 만약 ++이 뒤에있으면 출력후 증가
b는 increase 메소드 안에만 존재해서 리셋이 됨
728x90
LIST
'JAVA > Java' 카테고리의 다른 글
20201013_14 Arraylist이용한 학생정보 프로그램 (0) | 2020.10.13 |
---|---|
20201013_15 버블정렬, 2차원배열, Arraylist (0) | 2020.10.13 |
20201012_14 접근제한자, 오버로딩, 오버라이딩 (0) | 2020.10.12 |
20201008_13 (0) | 2020.10.08 |
20201008_13 메소드오버로딩 (0) | 2020.10.08 |
댓글