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

[๋ฐฑ์ค€][java][2753][์œค๋…„]

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

 

import java.util.Scanner;

// 2753	์œค๋…„
public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int year = sc.nextInt();
		
		System.out.print(year%4 == 0 && (year%100 != 0 || year%400 == 0) ? 1 : 0);
	}
}
  • java์—์„œ % ํผ์„ผํŠธ ๊ธฐํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ๊ฐ’์˜ ๋‚˜๋จธ์ง€๋ฅผ ๊ตฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • 4 ์˜ ๋ฐฐ์ˆ˜๋ผ๋ฉด 20 % 4๋ฅผ ํ–ˆ์„ ๊ฒฝ์šฐ 0์ด ๋‚จ๊ณ , 21 % 4๋ฅผํ•˜๋ฉด 1์ด ๋‚จ์Šต๋‹ˆ๋‹ค.
  • ๋”ฐ๋ผ์„œ ๋ฐฐ์ˆ˜๋ฅผ ๊ตฌํ•˜๋ ค๋ฉด ๋‚˜๋จธ์ง€๊ฐ€ 0์ธ์ง€ ์•„๋‹Œ ์ง€๋งŒ ํ™•์ธํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

 

 

 

๋ฐ˜์‘ํ˜•