π§© νμ΅ λ¨μ : μ°μ°μ(operator)
π νμ΅ λμ : <Javaμ μ μ 3ν>(λ¨κΆ μ± μ )
βμ°μ°μ μμ μμ© νμ΅ μλ£(2021.12.25)
μμ©A.
package com.reminder.exercises;
public class Ex10_95 {
public static void main(String[] args) {
/* println()μκ² λμ
λλ μμ μ°¨μ΄ */
int i = 3, j = 3;
System.out.println(i++);
System.out.println(++j);
System.out.println("i = " + i + ", j = " + j);
/* λΆνΈ μ°μ°μ */
int k = -5;
k = -k;
System.out.println(k);
}
}
3
4
i = 4, j = 4
5
μμ©B.
package com.reminder.exercises;
public class Ex11_104 {
public static void main(String[] args) {
char ch = 'a';
for(int i=0; i < 26; i++) {
System.out.print(ch++);
}
System.out.println();
ch = 'A';
for(int i=0; i < 26; i++) {
System.out.print(ch++);
}
System.out.println();
ch = '0';
for(int i=0; i < 10; i++) {
System.out.print(ch++);
}
}
}
abcdefghijklmnopqrstuvwxyz
ABCDEFGHIJKLMNOPQRSTUVWXYZ
0123456789
μμ©C.
package com.reminder.exercises;
public class Ex12_105 {
public static void main(String[] args) {
/* λμλ¬Έμ λ³κ²½ */
char ch = 'A';
char lowerCase = (char)(ch + 32);
System.out.println("ch = " + ch + ", lowerCase = " + lowerCase);
ch = 'a';
char upperCase = (char)(ch - 32);
System.out.println("ch = " + ch + ", upperCase = " + upperCase);
}
}
ch = A, lowerCase = a
ch = a, upperCase = A
μμ©D. μμμ μ리 λ²λ¦¬κΈ° / λ°μ¬λ¦ΌνκΈ° A. νλ³ν μ΄μ©, B. Math.round() μ΄μ©
- roundλ©μλλ λ§€κ°λ³μλ‘ λ°μ κ°μ μμμ 첫째μ리μμ λ°μ¬λ¦Όνκ³ → μ μλ‘ κ²°κ³Όκ°μ λ°ννλ€.
- (Math.round(piNum)); = 3
package com.reminder.exercises;
public class Ex13_106 {
public static void main(String[] args) {
/* μμμ μ리 λ²λ¦¬κΈ° */
float pi = 3.141592f;
/* 1. μΆλ ₯κ° 3141.592 */
// float a = pi * 1000f;
// System.out.println(a);
/* 2. μΆλ ₯κ° 3141.0 */
// float b = (int)(pi * 1000);
// System.out.println(b);
float result = (int)(pi * 1000) / 1000f;
System.out.println(result);
/* λ°μ¬λ¦ΌνκΈ° */
double piNum = 3.141592;
/* A. νλ³ν μ΄μ© */
System.out.println((int)(piNum * 1000 + 0.5) * 0.001);
System.out.println((int)(piNum * 1000 + 0.5) / 1000.0);
/* B. Math.round() μ΄μ© */
System.out.println(Math.round(piNum));
System.out.println(Math.round(piNum * 100));
System.out.println((Math.round(piNum * 1000) / 1000.0));
}
}
3.141
3.142
3.142
3
314
3.142
μμ©E. String κ° λΉκ΅ / equals() / equalsIgnoreCase()
package com.reminder.exercises;
import java.util.Scanner;
public class Ex14_113 {
public static void main(String[] args) {
/* λ¬Έμμ΄ λΉκ΅ */
Scanner scanner = new Scanner(System.in);
System.out.print("ν 1. μ¬κ³Ό, λΈκΈ°, λ°°? > ");
String fruit = scanner.nextLine();
System.out.printf("μ¬κ³Όλ₯Ό κ³ λ₯΄μ
¨κ΅°μ ? %b%n", fruit.equals("μ¬κ³Ό"));
System.out.printf("λΈκΈ°λ₯Ό κ³ λ₯΄μ
¨κ΅°μ ? %b%n", fruit.equals("λΈκΈ°"));
System.out.printf("λ°°λ₯Ό κ³ λ₯΄μ
¨κ΅°μ ? %b%n", fruit.equals("λ°°"));
System.out.print("ABCλ₯Ό μ
λ ₯νμΈμ > ");
String abc = scanner.nextLine();
System.out.printf("ABC ? %b%n", abc.equals("ABC"));
System.out.printf("abc ? %b%n", abc.equals("abc"));
System.out.printf("ABC λλ abc ? %b%n", abc.equalsIgnoreCase("ABC"));
}
}
ν 1. μ¬κ³Ό, λΈκΈ°, λ°°? > μ¬κ³Ό
μ¬κ³Όλ₯Ό κ³ λ₯΄μ ¨κ΅°μ ? true
λΈκΈ°λ₯Ό κ³ λ₯΄μ ¨κ΅°μ ? false
λ°°λ₯Ό κ³ λ₯΄μ ¨κ΅°μ ? false
ABCλ₯Ό μ λ ₯νμΈμ > abc
ABC ? false
abc ? true
ABC λλ abc ? true
'Java' μΉ΄ν κ³ λ¦¬μ λ€λ₯Έ κΈ
[JAVA/μμ κ³Όμ ] λ°λ³΅λ¬Έ, λΆκΈ°λ¬Έ practice (0) | 2021.12.26 |
---|---|
[μλ°μ μ μ] Ch 4. μ μ΄λ¬Έ μ°μ΅λ¬Έμ νμ΄ (0) | 2021.12.25 |
[μλ°μ μ μ] Ch 3. μ°μ°μ μ°μ΅λ¬Έμ νμ΄ (0) | 2021.12.25 |
[JAVA] 4-3. λΆκΈ°λ¬Έ break, continue (0) | 2021.12.25 |
λ°λ³΅λ¬Έ μμ Quiz (0) | 2021.12.24 |