728x90

연산자 4

[JAVA] 하나의 정수를 입력받아 1부터 입력받은 정수까지의 짝수를 차례대로 출력하는 프로그램

하나의 정수를 입력받아 1부터 입력받은 정수까지의 짝수를 차례대로 출력하는 프로그램 정수는 50이하 //긁지않은 개발자 public class Ex01 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = 0; do { System.out.print("1~50사이의 정수를 입력 : "); n = sc.nextInt(); } while (n 50); for (int i = 2; i

[JAVA] JAVA 산술연산자

JAVA 산술연산자 산술 연산자 : + - * / %(나머지) //긁지않은 개발자 public class Ex01 { public static void main(String[] args) { int i = 20, j = 10; int k = i + j; System.out.println(i + " + " + j + " = " + k); //20 + 10 = 30 k = i - j; System.out.println(i + " - " + j + " = " + k); // 20 - 10 = 10 k = i * j; System.out.println(i + " * " + j + " = " + k); // 20 * 10 = 200 k = i / j; System.out.println(i + " / " + j +..

[JAVA] JAVA 숫자 %로 나눠서 출력하기 (년,월,일 응용)

%(나머지) //긁지않은 개발자 public class Ex01 { public static void main(String[] args) { String birth1 = "123456"; int birth2 = 123456; System.out.println(birth2/10000); System.out.println(birth2/100%100); System.out.println(birth2%10000/100); System.out.println(birth2%100); System.out.println(birth1.substring(0,2)); System.out.println(birth1.substring(2,4)); System.out.println(birth1.substring(4)); } } 실..

[JAVA] 연산자와 연산식

연산이란 ? 프로그램에서 데이터를 처리하여 결과를 산출하는 것을 연산이라고 한다. 단항 연산자 : ++x; 이항 연산자 : x+ y; 삼항 연산자 : (sum>90) "A" : "B"; 연산식은 반드시 하나의 값을 산출한다. 다음과 같이 x와 y 변수의 값을 더하고 나서 result변수에 저장한다. int result = x+ y; 연산식은 다른 연산자의 피연산자 위치에도 올 수 있다. x와y 변수의 값을 더하고 나서 5보다 작은지 검사한 후 결과값(true 또는 false)을 result 변수에 저장한다. boolean result = (x+y) >>) 대입 연산자 단순 대입 연산자 변수 = 피연산자 설명 : 우측의 피연산자의 값을 변수에 저장 삼항 연산자 삼항 연산자는(?:)는..

JAVA/JAVA 정리 2023.05.04
728x90