728x90 밍글링글링399 [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. [JAVA] ch03-27. 삼항 연산자 public class Ex27 { // 삼항 연산자 public static void main(String[] args){ int x = 10; int y = -10; int abcX = (x >= 0) ? x : -x; int abcY = (y >= 0) ? y : -y; System.out.println("x = 10 is, absolute x is " + abcX); System.out.println("y = -10 is, absolute y is "+ abcY); } } JAVA/예제 2017. 8. 21. [JAVA] ch03-26. 논리 연산자 public class Ex26 { //논리연산자 public static void main(String[] args){ int x = 3; int y = 5; System.out.println("x is " + x + "y is " + y + ":"); System.out.println("x | y = " + (x | y)); System.out.println("x & y = " + (x & y)); System.out.println("x ^ y = " + (x ^ y)); System.out.println("true | false = " + (true | false)); System.out.println("true & false = " + (true & false)); System.out.printl.. JAVA/예제 2017. 8. 21. [JAVA] ch03-25. 문자 범위 public class Ex25 {//문자 범위 public static void main(String[] args){ char x = 'j'; if((x >= 'a' && x = 'A' && x JAVA/예제 2017. 8. 21. [JAVA] ch03-24. 실수형 강제형변환 public class Ex24 {//실수형끼리 강제형변환 낮은것에서 높은것으로 바꿀때 근사값으로 처리 public static void main(String[] args){ System.out.println(10.0d == 10.0f); System.out.println(0.1d == 0.1f); System.out.println(0.1f); System.out.println(0.1d); System.out.println((double)10.0f); System.out.println((double)0.1f); System.out.println(0.1d == (double)0.1f); System.out.println(0.1f == (double)0.1f); System.out.println((float.. JAVA/예제 2017. 8. 21. [JAVA] ch03-23. 비교 연산자 public class Ex23 {// 비교 연산자 = 형용사 public static void main(String[] args){ System.out.println( 10 == 10.0f); System.out.println('0' != 0 ); // 0은 유니코드값으로 48이다. != (다르다) System.out.println('A' == 65); int num = 5; if(num > 0 && num < 9 ) System.out.println("5는 0~9 사이에 있다."); } } JAVA/예제 2017. 8. 21. [JAVA] ch03-22. 쉬프트 연산자 public class Ex22 { // 쉬프트 연산자 public static void main(String[] args){ int temp; System.out.println(-8); System.out.println(Integer.toBinaryString(-8)); System.out.println(); temp = -8 1; // -8/2 System.out.println("-8 >> 1 = " + temp); System.out.println(Integer.toBinaryString(temp)); System.out.println(); temp = -8 >> 2; // -8/4 System.out.println("-8 >> 2 = " + temp); System.out.println(Integ.. JAVA/예제 2017. 8. 21. [JAVA] ch03-21. 나머지값 public class Ex21 {//나머지값 public static void main(String[] args){ System.out.println(-10 % 8); System.out.println(10 % -8); System.out.println(-10 % -8); } } JAVA/예제 2017. 8. 21. 이전 1 ··· 24 25 26 27 28 29 30 ··· 34 다음 728x90