๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Java

[Java] ์ž…๋ ฅ๊ฐ’ ์ฒ˜๋ฆฌ

by ๐Ÿ’œautumn 2020. 8. 1.

1. Scanner

Scanner sc=new Scanner(System.in);
nextInt() ์ˆซ์ž ๋‹จ์ผ ์ˆซ์ž๊ฐ’๋งŒ ์ž…๋ ฅ > Enter, ๊ณต๋ฐฑ ์ž…๋ ฅ์‹œ ์ข…๋ฃŒ
next() ๋ฌธ์ž์—ด ๋ฌธ์ž์—ด ํ•œ ์ค„๋งŒ ์ž…๋ ฅ > ๊ณต๋ฐฑ์‹œ ๋‹ค์Œ ๊ฐ’์œผ๋กœ ์ธ์‹, Enter์ž…๋ ฅ์‹œ ์ž…๋ ฅ ์ข…๋ฃŒ
nextLine() ๋ฌธ์ž์—ด ๋ฌธ์ž์—ด ์—ฌ๋Ÿฌ ์ค„๋„ ์ž…๋ ฅ๊ฐ€๋Šฅ > Enter๋„ ๋ฌธ์ž์—ด๋กœ ์ทจ๊ธ‰ (๋‹จ, ๋‹ค์Œ ์ž…๋ ฅ์š”์ฒญ์œผ๋กœ ๋„˜์–ด๊ฐ)

 

 

 

2. BufferedReader

    : ๋ฒ„ํผํด๋ž˜์Šค๋Š” ์ž…๋ ฅ๊ฐ’์„ ํ†ต์งธ๋กœ ์ธ์‹ํ•˜๊ธฐ๋•Œ๋ฌธ์— Scanner๋ณด๋‹ค ์—ฐ์‚ฐ์‹œ๊ฐ„ ์šฐ์ˆ˜ (์‚ฌ์šฉ๊ถŒ์žฅ)

BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
read() ์ž…๋ ฅ๊ฐ’ int์ธ ๊ฒฝ์šฐ (Enter, ๊ณต๋ฐฑ์‹œ ์ž…๋ ฅ ์ฆ‰์‹œ ์ข…๋ฃŒ)
readLine() ์ž…๋ ฅ๊ฐ’ String+Enter์ธ ๊ฒฝ์šฐ

 

3. StringTokenizer

   : String์ด์ง€๋งŒ, ๊ณต๋ฐฑ ๋‹จ์œ„๋กœ ์ž˜๋ผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ

   : ๋ฒ„ํผํด๋ž˜์Šค์˜ readLine()๊ณผ ํ•จ๊ป˜ ์‚ฌ์šฉ!

   : ์ˆซ์ž๋ฅผ ์ €์žฅํ•˜๊ณ  ์‹ถ์€ ๊ฒฝ์šฐ Integer.parsInt(str) ํ™œ์šฉ!

StringTokenizer st=new StringTokenizer(br.readLine());
nextToken() ๊ณต๋ฐฑ๋‹จ์œ„๋กœ ์ž๋ฅผ์ˆ˜ ์žˆ๋Š” ๋ฉ”์†Œ๋“œ > ์ผ์ข…์˜ split

 

๋Œ“๊ธ€