Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- CSS
- html
- Algorithm
- javascript
- DoM
- architecture
- Linux
- php
- computer
- control
- MIPS
- Pipelining
- web
- while
- mysql
- DATAPATH
- github
- Java
- for
- python
- instruction
- function
- DB
- react
- MacOS
- Class
- system
- XML
- data structure
- DS
Archives
- Today
- Total
YYYEJI
[JAVA] 사용자로부터 값 입력받기 (Scanner) 본문
728x90
사용자로부터 값을 입력받기 위해서는 Scanner 함수를 사용해야 됩니다.
import java.util.Scanner;
을 먼저 선언해주고 시작하겠습니다.
먼저 객체를 만들어줘야 합니다.
Scanner s = new Scanner(System.in);
객체를 만든 후에 Scanner 관련 method를 사용할 수 있습니다.
int i= s.nextInt();
double d= s.nextDouble();
Boolean b = s.nextBlooean();
String sentence= s.nextLine();
예제를 살펴보겠습니다.
① nextInt
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
int n1 = s.nextInt();
System.out.print("You endted " + n1 + ".");
}
② nextDouble
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
double n1 = s.nextDouble();
System.out.print("You endted " + n1 + ".");
}
③ next
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
String n1 = s.next();
System.out.print("You endted " + n1 + ".");
}
✓ 단어를 읽음
④ nextLine
public static void main(String[] args) {
Scanner s = new Scanner (System.in);
String n1 = s.nextLine();
System.out.print("You endted " + n1 + ".");
}
✓ 문장을 읽음
◡̈
'Java' 카테고리의 다른 글
[JAVA] 자바에서 주석(comment) 처리하는 방법 (0) | 2022.10.23 |
---|---|
[JAVA] Delimiter란? (0) | 2022.10.23 |
[JAVA] 자바 console에 결과 출력하기 (0) | 2022.10.23 |
[JAVA] Truncates 란? (0) | 2022.10.23 |
[JAVA] String 클래스 매소드 정리 (0) | 2022.10.23 |