switch 문
- 형식
switch(변수(정수형 상수)){
case 값_1(상수):
stmt1;
break;
case 값_2:
stmt2;
break;
case 값_n:
stmt3;
break;
default:
stmt4;
}
switch(변수) 변수값은 byte,short,int char
값이올수있다.(long 은안됨)
*/
public class SwichTest {
public static void main(String[] args) {
int level = 123;// 1 ~ 5 까지의 레벨이 존재
String msg="";
switch (level) {
case 1:
msg="초보시군요";
break;
case 2:
msg="좀하시는군요";
break;
case 3:
msg="잘하시네요";
break;
case 4:
msg="사부님";
break;
case 5:
msg="사부님";
break;
default:
msg="레벨은 1~5사이의 정수입니다";
break;
}//end switch
System.out.println(msg);
}//end main
}//end class
---------------------------------------
/*
반복문
stmt1;
while(조건문){
//조건문--> 논리형데이타를 반환하는 식
stmt2;
}
stmt3;
흐름 stmt1 -->조건식의 데이타가 true인동안실행--> stmt3
*/
public class WhileTest {
public static void main(String[] args) {
//무한실행
//while (true){
// System.out.println("오잉");
//}
boolean isAlive=true;
int i=0;
while (isAlive) {
System.out.println("i="+i);
i++;
if(i==10){
isAlive=false;
}
if(i==10){
System.out.println("isAlive=false");
}
}
boolean b1=true;
int j=0;
while (b1) {
System.out.println("j="+j);
j++;
if(i==10){
break;//이문장을 만나면 loop block를 빠져나간다.
}
if(j==10){
System.out.println("isAlive=false");
}
}
int i2=0;
while (i2<10) {
System.out.println("i2="+i2);
i2++;
}
int i3=0;
while (i3<10){
System.out.println("i3="+i3);
i3++;
}
}
}
--------------------------------------------
public class WhilePrine { public static void main(String[] args) { int i2=0; while (i2<10){ System.out.println("i2="+i2); i2++; } /* * 알파벳대문자출력 */ /* * char c= 'A'; while(c<='Z'){ System.out.print(c+" "); System.out.println(); c++; } * 알파벳대문자 출력(4개찍고 개행) char han='ㄱ'; while(han<='햏'){ System.out.print(han); han++; */ char eng = 'a'; while (eng <='z'){ if(eng%4==0){ System.out.println(eng); } eng++; } /* * 짝수 홀수 구분하기~~ */ int i = 0; while (i<79){ if(i%2==0){ System.out.println(i+"짝수입니다"); }else{ System.out.println(i+"홀수입니다"); } i++; } } }
/*
반복문
stmt1;
while(조건문){
//조건문--> 논리형데이타를 반환하는 식
stmt2;
}
stmt3;
흐름 stmt1 -->조건식의 데이타가 true인동안실행--> stmt3
*/
public class WhileTest {
public static void main(String[] args) {
//무한실행
//while (true){
// System.out.println("오잉");
//}
boolean isAlive=true;
int i=0;
while (isAlive) {
System.out.println("i="+i);
i++;
if(i==10){
isAlive=false;
}
if(i==10){
System.out.println("isAlive=false");
}
}
boolean b1=true;
int j=0;
while (b1) {
System.out.println("j="+j);
j++;
if(i==10){
break;//이문장을 만나면 loop block를 빠져나간다.
}
if(j==10){
System.out.println("isAlive=false");
}
}
int i2=0;
while (i2<10) {
System.out.println("i2="+i2);
i2++;
}
int i3=0;
while (i3<10){
System.out.println("i3="+i3);
i3++;
}
}
}
--------------------------------------------
public class WhilePrine { public static void main(String[] args) { int i2=0; while (i2<10){ System.out.println("i2="+i2); i2++; } /* * 알파벳대문자출력 */ /* * char c= 'A'; while(c<='Z'){ System.out.print(c+" "); System.out.println(); c++; } * 알파벳대문자 출력(4개찍고 개행) char han='ㄱ'; while(han<='햏'){ System.out.print(han); han++; */ char eng = 'a'; while (eng <='z'){ if(eng%4==0){ System.out.println(eng); } eng++; } /* * 짝수 홀수 구분하기~~ */ int i = 0; while (i<79){ if(i%2==0){ System.out.println(i+"짝수입니다"); }else{ System.out.println(i+"홀수입니다"); } i++; } } }
잘하네~
답글삭제잘하네~근데 뭐임?!
답글삭제