728x90 JAVA126 [JAVA] ch04-13. FOR 문 3 public class Ex13 { public static void main(String[] args){ int sum = 0; for(int i=0; i JAVA/예제 2017. 8. 21. [JAVA] ch04-12. FOR 문 2 public class Ex12 { public static void main(String[] args){ int sum = 0; int i = 0 ; for(; i JAVA/예제 2017. 8. 21. [JAVA] ch04-11. FOR 문 public class Ex11 { public static void main(String[] args){ int sum = 0; for(int i=1; i JAVA/예제 2017. 8. 21. [JAVA] ch04-09. 경품 추천 public class Ex09 { // 경품 추천 public static void main(String[] args){ int score = (int)(Math.random()*10)+1; String msg = ""; score *= 100; msg = "score: " + score + ", prize: "; switch(score){ case 1000: msg += "fridge, "; case 900: msg += "tv, "; case 800: msg += "notebook, "; case 700: msg += "bicycle, "; default: msg += "ballpen"; } System.out.print(msg+"\n"); } } JAVA/예제 2017. 8. 21. [JAVA] ch04-08. SWITCH ~ CASE 문 3 public class Ex08 { public static void main(String[] args){ int score = 3; switch(score*100){ case 100: System.out.println("score: 100"); case 200: System.out.println("score: 200"); case 300: System.out.println("score: 300"); case 400: System.out.println("score: 400"); default: System.out.println("none"); } } } JAVA/예제 2017. 8. 21. [JAVA] ch04-07. SWITCH ~ CASE 문 2 public class Ex07 { public static void main(String[] args){ char ch = (char)(Math.random()*4+'A'); int score = 0; switch(ch){ case 'A': score = 90; break; case 'B': score = 80; break; case 'C': score = 70; break; case 'D': score = 60; break; } System.out.printf("score : %d", score); } } JAVA/예제 2017. 8. 21. [JAVA] ch04-06. SWITCH ~ CASE 문 public class Ex06 { public static void main(String[] args){ int score = (int)(Math.random() * 10)+1; // 시작값이 1 시작값으로부터 10개 중 랜덤으로 1개 int tmp = score * 100; switch(tmp){ case 100: System.out.printf("score %d : bicycle", tmp); break; case 200: System.out.printf("score %d : TV", tmp); break; case 300: System.out.printf("score %d : Aircon", tmp); break; default: System.out.println("no price"); } } } JAVA/예제 2017. 8. 21. [JAVA] ch04-05. 등급 나누기 public class Ex05 { public static void main(String[] args){ int score = 82; String grade = ""; System.out.println("Score : "+score); if(score > 90){ grade = "A"; if(score > 88) grade += "+"; else if(score = 80){ grade = "B"; if(score > 78) grade += "+"; else if(score = 70){ grade = "C"; } System.out.println(grade + "등급"); } } JAVA/예제 2017. 8. 21. [JAVA] ch04-04. 삼항 연산 public class Ex04 { public static void main(String[] args){ int score = 45; char grade = 0; grade = (score>=90)? 'A' :((score>=80)? 'B':'C'); System.out.print(grade + "등급"); String s = ""; if(s.equals("C")){} } } JAVA/예제 2017. 8. 21. [JAVA] ch04-03. IF ~ ELSE IF ~ ELSE 문 public class Ex03 { public static void main(String[] args){ int score = 95; char grade = 0; if(score >= 90){ grade = 'A'; }else if(score >= 80){ grade = 'B'; }else{ grade = 'C'; } System.out.println(grade + "등급"); } } JAVA/예제 2017. 8. 21. [JAVA] ch04-02. IF ~ ELSE 문 public class Ex02 { public static void main(String[] args){ int visitCount = 5; if(visitCount < 1) { System.out.print("첫방문"); }else{ System.out.println("재방문"); } } } JAVA/예제 2017. 8. 21. [JAVA] ch04-01. IF문 public class Ex01 { public static void main(String[] args){ int visitCount = 0; if(visitCount < 1){ System.out.println("환영합니다."); } } } JAVA/예제 2017. 8. 21. 이전 1 ··· 4 5 6 7 8 9 10 11 다음 728x90