Java/2012.04 강좌
4일차
Bohemian life
2012. 4. 6. 10:33
public class SwitchStudy { //main 안에 있는 소스를 자동으로 실행해라 public static void main(String[] args) { int score=100; switch(score/10){//()안에 숫자가 옵니다. case 10 : System.out.println("A학점"); System.out.println("잘했음"); break;//swich문을 빠져나와라 case 9 : System.out.println("B학점"); case 8 : System.out.println("C학점"); break; case 7 : System.out.println("D학점"); break; case 6 : System.out.println("F학점"); System.out.println("나머지 공부"); break; //if else문의 else 와 같은 역할을 합니다. default : System.out.println("60점 이하임"); } int number= 88877; /*위의 number가 7의 배수인지 확인하시오 결과 : number값 ? 는 7의 배수 입니다. 결과 : number값 ? 는 7의 배수 아닙니다. */ switch(number%7){ case 0 :System.out.println("넘버값"+number+"는 7의 배수 입니다."); break; default :System.out.println("넘버값"+number+"는 7의 배수 아닙니다."); } if(number%7==0){ System.out.println("넘버값"+number+"는 7의 배수 입니다."); }else{ System.out.println("넘버값"+number+"는 7의 배수 아닙니다."); } } public static void main2(String[] args){ System.out.println("안녕"); } }