티스토리 뷰

JAVA 160531-6 switch 활용

package pack;


import java.util.Scanner;


public class Test8switch {


public static void main(String[] args) {

// 조건 판단문 switch

int nai = 32;

nai = nai / 10 * 10;

//System.out.println(nai);

switch(nai){

case 30:

System.out.println("삼십대");

System.out.println("인생의 바쁜 날 많음");

break;

case 40:

System.out.println("사십대 중년");

System.out.println("그래도 바쁨");

break;

default:

System.out.println("기타");

break;

}

double time2 = Math.random();

System.out.println(time2);

//double time = Math.random();

int time = (int)(Math.random() * 4) + 8; // 정수 랜덤.

System.out.println(time);

switch (time){

case 8:

System.out.println("출근하자");

break;

case 9:

System.out.println("회의하자");

break;

case 10:

System.out.println("프로그램 짜자");

break;

default:

System.out.println("명상하기");

}

System.out.println("작업 계속");

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

//문제 : 키보드로 부터 년과 월을 각각 입력 받아

// 해당년, 월의 날 수를 출력. 윤년을 체크.

// 윤년은 해당년이 4의 배수 이고, 100의 배수가 아니거나 400의 배수이면 윤년

//출력 : ****년 **월은 **일 윤년(평년)

//\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

System.out.println("\n\n\n\n");

int yun;

int wol = 0;

Scanner sc = new Scanner(System.in);

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

int year = sc.nextInt();

System.out.print("몇월? ");

int mon = sc.nextInt();

yun = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0))?0:1;

switch(mon){

case 1:

wol = 31;

break;

case 2:

wol = (yun==0)?29:28;

break;

case 3:

wol = 31;

break;

case 4:

wol = 30;

break;

case 5:

wol = 31;

break;

case 6:

wol = 30;

break;

case 7:

wol = 31;

break;

case 8:

wol = 31;

break;

case 9:

wol = 30;

break;

case 10:

wol = 31;

break;

case 11:

wol = 30;

break;

case 12:

wol = 31;

break;

}

System.out.println(year + "년 " + mon + "월은 " + wol + "일 " + ((yun==0)?"윤년":"평일"));

}


}








'📁 공부정리 > JAVA' 카테고리의 다른 글

JAVA 160601-1 for  (0) 2016.06.02
ㄱㅇㅅ님 자료 참고(while)  (0) 2016.06.01
빠른코더가 되기 위한 이클립스 단축기!  (0) 2016.05.31
JAVA 160531-5 if문 연습  (0) 2016.05.31
JAVA 160531-4 정수 값 처리  (0) 2016.05.31

Recent Comments