๐Ÿ•ธ Algorithm/๐Ÿ•ธ ๋ฐฑ์ค€ BaekJoon

[๋ฐฑ์ค€][java][11382][๊ผฌ๋งˆ ์ •๋ฏผ]

๋‰ด์ด NUEY 2023. 9. 10. 20:09
๋ฐ˜์‘ํ˜•

 

import java.util.Scanner;
//11	11382	๊ผฌ๋งˆ ์ •๋ฏผ
public class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		String input = scanner.nextLine();
		
		String[] inputArr = input.split(" ");
		
		long sum = 0;
		
		for (String i : inputArr) {
			sum += Long.parseLong(i);
		}
		
		System.out.print(sum);
	}
}
  • String๊ฐ’์„ ๋ฐ›์€ ํ›„์— Split()์„ ์ด์š”ํ•ด ์ž˜๋ผ String๋ฐฐ์—ด๋กœ ๋งŒ๋“ค์–ด์ค๋‹ˆ๋‹ค.
  • for๋ฌธ์„ ํ†ตํ•ด ๊ฐ’์„ ๋ชจ๋‘ ๋”ํ•˜๋Š”๋ฐ
    Integer์˜ ๋ฒ”์œ„๋Š” 10์˜ 9์Šน๊นŒ์ง€์ธ๋ฐ ๋ฌธ์ œ๋Š” 10์˜ 12์Šน๊นŒ์ง€ ๊ตฌํ•ด์•ผํ•˜๊ธฐ์— Longํƒ€์ž…์„ ์จ์ค๋‹ˆ๋‹ค.
  • ์ด ๋•Œ String → long ํƒ€์ž…์œผ๋กœ ๋ณ€ํ™˜ํ•ด์•ผ ํ•˜๊ธฐ ๋•Œ๋ฌธ์— Mapper Class์ธ Long.parseLong()์„ ์ด์šฉํ•ฉ๋‹ˆ๋‹ค.

 

 

๋ฐ˜์‘ํ˜•