public class Main {
public static void main(String[] args) {
System.out.println("Hello world!"); //10초 걸림
System.out.println("Hello world!"); //10~12초
System.out.println("출력하고자 하는 문자");
}
}
System.out.print() → 시스템의 표준 출력을 의미하는 함수
System.out.println() → System.out.print() + 줄바꿈 기능
Ctrl + ALT + Shift + L
int x = 5; // → x 는 변수
int y = 10 + x; // → 여기서 x는 값일 뿐이다.
System.out.println(y + 5); //결과는 → 15;
/*
"="을 기준으로 좌측에 있으면 변수 우측에 있으면 값이다.
같은 공간 내에서 같은 변수명을 사용할 수 없다.
변수명을 지을때 숫자가 앞에 들어가면 안된다.
*/
→ 크게 2가지 자료형이 존재한다.
기본형
참조형 → 주소값
이 들어있다.
→ 조건이 참이여야지 실행한다.
조건 판별과 논리 연산자
class Main {
public static void main(String[] args) {
int a = 30;
if(a > 30) {
System.out.println("참 실행");
}else{
System.out.println("거짓 실행안함");
}
}
}
class Main {
public static void main(String[] args) {
int a = 30;
if(a > 30) {
System.out.println("숫자가 30보다 크다.");
}else if(a > 15){
System.out.println("숫자가 16 ~ 30 입니다.");
}else{
System.out.println("숫자가 14보다 작습니다.");
}
}
}
class Main {
public static void main(String[] args) {
//while문을 이용해서 10~1 까지의 합 구하기
int i=10;
int sum =0;
//while(조건){}
while(i > 0){
sum = sum + i;
//i값은 감소 시키지 않으면 무한루프가 돌게된다.
//i를 감소시키지 않으면 while문을 벗어나지 못한다.
i--; //감소 연산
}
System.out.println(sum);
}
}
class Main {
public static void main(String[] args) {
int sum =0;
//for(초기값; 조건; 증감){}
for(int i=1; i<=10; i++){
sum += i;
}
System.out.println(sum);
}
}
메모리 이야기
→ 지역변수는 Stack이라는 메모리 공간에 생성되고 객체(인스턴스)는 Heap 메모리 공간에 생긴다.
int a = 5;
int[] b = new int[3];
그러면 변수는 언제 사라지는가?
가비지 콜렉터
가 해당 변수를 없앤다.간단한 용어 정리