문제


사전 구상

  • 자연수 n 이 주어지면 n을 2로 나눠서 나머지가 0이면 짝수 출력! 아니면 홀수 출력

package lv_0;

import java.util.Scanner;

public class oddeven {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();

		int result = n % 2;
		
		if (result == 0) {
			System.out.printf("%d is even", n);
		} else {
			System.out.printf("%d is odd", n);
		}

	}

}

 

결과


https://github.com/Beast-IT/Programmers.git

 

GitHub - Beast-IT/Programmers: 코딩테스트 연습!

코딩테스트 연습! Contribute to Beast-IT/Programmers development by creating an account on GitHub.

github.com

Github에 들어가시면 원본 코드 보실 수 있습니다.

+ Recent posts