Recent Posts
Recent Comments
밍쎄의 코딩공간
변수와 데이터 타입 본문
01. 변수
: 사용되는 저장과 참조를 위해 할당된 메모리 공간
- 선언 : 변수를 컴파일러에게 알려주는 것
- 초기화 : 변수를 사용하기 위해 공간에 특정 값으로 할당해주는
public class Main {
public static void main(String[] args){
int age; //declaration
double value;
age = 27; //initializtion
//age라고 선언한 변수에 27이란 값으로 초기화
int num = 1; //선언과 동시에 초기화
}
}
02. 입력과 출력
- 실행 시 Argument로 넘겨 받는 방법
- 실행 시 키보드로 입력
1. print(data) : data만 출력
2. printf( "형식", data ) : 형식에 맞춰 data 출력
3. println(data) : data를 출력하고 다움 행으로 이동
import java.util.Scanner;
public class InputAndOutput {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
//Enter가 입력되기 전까지의 내용을 읽음
String inputData = scanner.nextLine();
//inputData
System.out.printf(inputData);
//이름 : inputData
System.out.printf("이름 : %s", inputData);
//inputData
//
System.out.println(inputData);
}
}
03. 타입변환
- int -> char
- Double -> int
- byte<short<int<long<float<double
소스코드 : 제로베이스 벡엔드 스쿨
728x90
'개념정리' 카테고리의 다른 글
데이터베이스 - 01 (0) | 2023.08.01 |
---|---|
운영체제 (0) | 2023.07.30 |
자료구조 (0) | 2023.07.29 |
시간복잡도 (0) | 2023.07.28 |
Collection (0) | 2023.07.14 |