본문 바로가기

자바/문법

if ~ else 문(평년, 윤년)

예제)


import java.io.IOException;

import java.io.InputStreamReader;

import java.io.BufferedReader;


public class Test14 {

public static void main(String[] args) throws IOException {

BufferedReader br=new BufferedReader(

new InputStreamReader(System.in));


int a,b,c;


System.out.print("년도 ?");

a=Integer. parseInt(br.readLine());



if(a%4==0&&a%100!=0||a%400==0) {

System.out.println(a+": 윤년");

} else

System.out.println(a+": 평년");



System.out.println("종료 !!!");


}

}


결과) 년도를 입력받아 평년인지 윤년인지 판별


년도 ?2013

2013: 평년

종료 !!!