[Java] ๐Ÿ“Scanner์‚ฌ์šฉ

JISO.Oยท2022๋…„ 4์›” 20์ผ
0

Java

๋ชฉ๋ก ๋ณด๊ธฐ
1/8
post-thumbnail

์ž๋ฐ” Scanner ์‚ฌ์šฉ ๋ฐฉ๋ฒ•

์ž๋ฐ”์—์„œ Scanner๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š”
import java.util.Scanner;
Scanner scan = new Scanner(System.in);
์ด ๋‘ ๋ฌธ์žฅ์„ ๊ผญ ์จ์ค˜์•ผ ํ•œ๋‹ค.

import java.util.Scanner;
public class ํด๋ž˜์Šค์ด๋ฆ„{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);

์ด์ œ ์‚ฌ์šฉ์ž๋กœ๋ถ€ํ„ฐ ๋ฌด์–ธ๊ฐ€๋ฅผ ์ž…๋ ฅ๋ฐ›๊ธฐ ์œ„ํ•ด์„œ๋Š”
ํƒ€์ž… ๋ณ€์ˆ˜ = scan.next๋ณ€์ˆ˜(); ๋ฅผ ์ž…๋ ฅํ•ด์•ผ ํ•œ๋‹ค.

  • ์ •์ˆ˜ํ˜•
int a = scan.nextInt();
  • ์‹ค์ˆ˜ํ˜•
double b = scan.nextDouble();
  • ๋ฌธ์ž์—ด
    ๋ฌธ์ž์—ด์€ scan.next๋’ค์— ํƒ€์ž…์„ ์“ฐ์ง€ ์•Š์•„๋„ ๋œ๋‹ค.
String str = scan.next();

์ •์ˆ˜, ์‹ค์ˆ˜, ๋ฌธ์ž์—ด ์ž…๋ ฅ๋ฐ›๊ณ  ์ถœ๋ ฅํ•˜๊ธฐ

import java.util.Scanner;
public class Suse{
	public static void main(String args[]){
		Scanner scan = new Scanner(System.in);

		System.out.print("๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์„ธ์š” : ");
		String str = scan.next();
		System.out.println(str);

		System.out.print("์ •์ˆ˜๋ฅผ ํ•˜๋‚˜ ์ž…๋ ฅํ•˜์„ธ์š”.");
		int a =scan.nextInt();
		System.out.println(a);

		System.out.print("์‹ค์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š”.");
		double b = scan.nextDouble(); 
		System.out.println(b);
 
	}
}

์ถœ๋ ฅ
๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์„ธ์š” : <- '๋ฌธ์ž์—ด' ์ž…๋ ฅ
๋ฌธ์ž์—ด
์ •์ˆ˜๋ฅผ ํ•˜๋‚˜ ์ž…๋ ฅํ•˜์„ธ์š” : <- '3' ์ž…๋ ฅ
3
์‹ค์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : <- '5.8' ์ž…๋ ฅ
5.8

๐Ÿ–์ตœ์ข…๊ฒฐ๊ณผ๐Ÿ–
๋ฌธ์ž์—ด์„ ์ž…๋ ฅํ•˜์„ธ์š” : ๋ฌธ์ž์—ด
๋ฌธ์ž์—ด
์ •์ˆ˜๋ฅผ ํ•˜๋‚˜ ์ž…๋ ฅํ•˜์„ธ์š” : 3
3
์‹ค์ˆ˜๋ฅผ ์ž…๋ ฅํ•˜์„ธ์š” : 5.8
5.8

profile
๋ฏธ๋ฆผ๋งˆ์ด์Šคํ„ฐ๊ณ ๋“ฑํ•™๊ต์—์„œ ๊ฐœ๋ฐœ์„ ๊ณต๋ถ€์ค‘์ธ ํ•™์ƒ์ž…๋‹ˆ๋‹ค!

0๊ฐœ์˜ ๋Œ“๊ธ€