IfEx02.java-단일 if

CODEDRAGON Development/Java

반응형

조건문 - 단일 if (정수형 입력 받은 후 짝수 홀수 구분하기)

   

소스코드

   

  1. public class IfEx02 {
  2.    
  3.         public static void main(String[] args) {
  4.                  
  5.                 java.util.Scanner input = new java.util.Scanner(System.in);
  6.                  
  7.                 int a;
  8.                  
  9.                 System.out.print("정수형 데이터 하나를 입력 > ");
  10.                 a = input.nextInt();
  11.                                  
  12.                  
  13.                 if(a%== 1){   //홀수 체크
  14.                         System.out.print("홀수 입니다.");
  15.                          
  16.                 }else{  // 짝수
  17.                         System.out.print("짝수 입니다.");                 
  18.                 }      
  19.         }
  20. }


   

출력결과

   

   

   

   

반응형