일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 |
Tags
- 웹
- linux
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online강의
- 자바기본
- java기초
- 직장인자기계발
- 디자인패턴
- 자바기초
- 직장인인강
- 스프링
- javabasic
- 자바연습문제
- 디자인
- DB
- Spring
- ncs
- String
- 국비
- 재택근무
- 패캠챌린지
- 패스트캠퍼스
- DesignPattern
- 데이터베이스
- 리눅스
- js
- 패스트캠퍼스후기
- 자바
- java
- 자바예제
- 한번에끝내는JavaSpring웹개발마스터초격차패키지Online
Archives
- Today
- Total
FIF's 코딩팩토리
자바 기초 NCS교육과정(2)-연산자 본문
반응형
주석처리 된 것을 천천히 읽어보고, 직접 타이핑 해보세요
Java011_operator.java
package java0911_basic; public class Java016_print { public static void main(String[] args) { System.out.println("java"); System.out.println("jsp"); System.out.print("spring"); System.out.print("oracle\n"); /* * printf("출력형식", 값1, 값2..) * * 출력기호 * %s : 문자열 * %d : 정수 * %f : 실수 * %c : 문자 * %b : 논리 * %% : % * \ : 특수문자를 처리하는 기호 */ System.out.printf("%s\n","mybatis"); System.out.printf("%d\n",50L);//byte,short,int,long System.out.printf("%f\n",4.5F);//float, double System.out.printf("%c %b %d\n", 'a', true, 10); //소수점 첫번째 까지 출력을 한다.(반올림) System.out.printf("%.1f\n",4.54); //5는 총자릿수(소수점 포함) .1은 소수점 자릿수 System.out.printf("%5.1f\n",4.54); System.out.printf("%5.1f\n",34.56); System.out.printf("%5.1f\n",124.56); System.out.printf("%5.1f\n",5124.56); System.out.printf("%5.2f\n",4.56); System.out.printf("%5.2f\n",4.5); System.out.printf("%5.2f\n",24.567); System.out.printf("%5.2f\n",124.5); //-기호는 왼쪽 정렬 System.out.printf("%5.1f\n",4.56); System.out.printf("%-10s\n","korea"); //내 나이는 10살입니다. int age= 10; System.out.printf("내 나이는 %d살입니다.\n",age); //홍길동님의 평균은 95.0 이므로 A학점입니다. String name="홍길동"; float score=95.0f; char grade='A'; System.out.printf("%s님의 평균은 %.1f이므로 %c학점입니다.\n",name,score,grade); //3 + 2 = 5 int a=3; int b=2; System.out.printf("%d + %d = %d\n",a,b,a+b); //3 % 2 = 1 System.out.printf("%d %% %d = %d\n",a,b,a%b); //당신의 색깔은 "파랑"입니다. System.out.printf("당신의 색깔은 \"%s\"입니다.\n","파랑"); }//end main() }//end class
Java012_operator.java
package java0911_basic; public class Java012_operator { public static void main(String[] args) { int a = 4; int b = 5; int c = 7; //&&연산자의 좌변이 false이면 우변은 수행하지 않는다. boolean res=(++a > b) && (++b < c); System.out.println("a="+a); System.out.println("b="+b); System.out.println("res="+res); int x = 4; int y = 8; int z = 10; // ||연산자의 좌변이 true이면 우변은 수행하지 않는다. res = (z>++y) || (++x > y); System.out.println("x="+x);//4 System.out.println("y="+y);//9 System.out.println("res="+res);//true }//end main() }//end class
Java013_operator.java
package java0911_basic; /* * 조건연산자(삼항연산자) : * 식의 결과에 따라서 리턴해주는 갑이 여러개 일때 사용한다. * * 식 ? 참 : 거짓 * int res = true ? 1:0; * char res=false ? 'a':'A'; * * 식1 ? 참1 : 식2 ? 참2 : 거짓2 */ public class Java013_operator { public static void main(String[] args) { int total=21; int record=5; int page=total%record==0 ? total/record : total/record +1; System.out.println(page); }//end main() }//end class
Java014_operator.java
package java0911_basic; public class Java014_operator { public static void main(String[] args) { int a = 3; int b = 4; int res=0; //res = a + b; //System.out.println(res); //res=res+a; res += a; //res값이 저장되어 있어야 함 System.out.println(res); }//end main() }//end class
Java015_operator.java
package java0911_basic; /* * 연산자 우선순위 * 단항연산자(++,--,!) > 산술연산자 > 비교연산자 > 논리연산자 > 삼항연산자 > 대입연산자 * */ public class Java015_operator { public static void main(String[] args) { int a = 10; int b = 3; int c = 5; // ? : // && // a > b // a == b // a - b // res=7 int res = a>b && a==b ? a+b : a-b; System.out.println(res); }//end main() }//end class
Java016_print.java
package java0911_basic; public class Java016_print { public static void main(String[] args) { System.out.println("java"); System.out.println("jsp"); System.out.print("spring"); System.out.print("oracle\n"); /* * printf("출력형식", 값1, 값2..) * * 출력기호 * %s : 문자열 * %d : 정수 * %f : 실수 * %c : 문자 * %b : 논리 * %% : % * \ : 특수문자를 처리하는 기호 */ System.out.printf("%s\n","mybatis"); System.out.printf("%d\n",50L);//byte,short,int,long System.out.printf("%f\n",4.5F);//float, double System.out.printf("%c %b %d\n", 'a', true, 10); //소수점 첫번째 까지 출력을 한다.(반올림) System.out.printf("%.1f\n",4.54); //5는 총자릿수(소수점 포함) .1은 소수점 자릿수 System.out.printf("%5.1f\n",4.54); System.out.printf("%5.1f\n",34.56); System.out.printf("%5.1f\n",124.56); System.out.printf("%5.1f\n",5124.56); System.out.printf("%5.2f\n",4.56); System.out.printf("%5.2f\n",4.5); System.out.printf("%5.2f\n",24.567); System.out.printf("%5.2f\n",124.5); //-기호는 왼쪽 정렬 System.out.printf("%5.1f\n",4.56); System.out.printf("%-10s\n","korea"); //내 나이는 10살입니다. int age= 10; System.out.printf("내 나이는 %d살입니다.\n",age); //홍길동님의 평균은 95.0 이므로 A학점입니다. String name="홍길동"; float score=95.0f; char grade='A'; System.out.printf("%s님의 평균은 %.1f이므로 %c학점입니다.\n",name,score,grade); //3 + 2 = 5 int a=3; int b=2; System.out.printf("%d + %d = %d\n",a,b,a+b); //3 % 2 = 1 System.out.printf("%d %% %d = %d\n",a,b,a%b); //당신의 색깔은 "파랑"입니다. System.out.printf("당신의 색깔은 \"%s\"입니다.\n","파랑"); }//end main() }//end class
반응형
'Back-End > 국비 NCS교과과정' 카테고리의 다른 글
자바 기초 NCS교육과정(6)-반복문 for (0) | 2019.07.03 |
---|---|
자바 기초 NCS교육과정(5)-분기문 switch~case (0) | 2019.07.03 |
자바 기초 NCS교육과정(4)-조건문if (0) | 2019.07.03 |
자바 기초 NCS교육과정(3)-문제풀이 (0) | 2019.07.03 |
자바 기초 NCS교육과정(1)-hello start! (0) | 2019.07.02 |