import ch01.Average;
import org.junit.Test;
import java.math.BigInteger;
import java.util.*;
public class Chapter01 {
@Test
public void ex0101() {
// ì ì
int n = 200;
// 2ì§ì
String binary = Integer.toBinaryString(n);
// 8ì§ì
String octal = Integer.toOctalString(n);
// 16ì§ì
String hex = Integer.toHexString(n);
System.out.println("binary = " + binary);
System.out.println("octal = " + octal);
System.out.println("hex = " + hex);
}
@Test
public void ex0102() {
double n = 2;
// ìì
double inverse = 1 / n;
// 16ì§ì ë¶ëììì
String hex = Double.toHexString(inverse);
System.out.println("n = " + n);
System.out.println("inverse = " + inverse);
System.out.println("hex = " + hex);
}
@Test
public void ex02() {
Random random = new Random();
int y = 360; // 0 ~ 359
int n = random.nextInt();
System.out.println("n = " + n);
int n1 = (n % y + y) % y;
System.out.println("n1 = " + n1);
int n2 = Math.floorMod(n, y);
System.out.println("n2 = " + n2);
}
@Test
public void ex0301() {
// ì ì 3ê°
int n1 = 12;
int n2 = 9;
int n3 = 17;
int max = Integer.MIN_VALUE;
if (n1 > max) {
max = n1;
}
if (n2 > max) {
max = n2;
}
if (n3 > max) {
max = n3;
}
// 17
System.out.println("max = " + max);
}
@Test
public void ex0302() {
// ì ì 3ê°
int n1 = 157;
int n2 = 384;
int n3 = 95;
int max = Math.max(Math.max(n1, n2), n3);
// 384
System.out.println("max = " + max);
}
@Test
public void ex04() {
double min = Math.nextUp(0);
double max = Math.nextDown(Double.MAX_VALUE);
System.out.println("min = " + min);
System.out.println("max = " + max);
}
@Test
public void ex05() {
double d = Double.MAX_VALUE;
int i = (int) d;
System.out.println("double = " + d);
System.out.println("integer = " + i);
}
@Test
public void ex06() {
// ë°ë³µ íì
int loop = 1000;
for (int n = 1; n <= loop; n++) {
BigInteger result = BigInteger.ONE;
for (int j = 1; j <= n; j++) {
result = result.multiply(BigInteger.valueOf(j));
}
System.out.println(n + "! = " + result);
}
}
@Test
public void ex08() {
String s = "Slack brings all your communication together in one place. It's real-time messaging, archiving and search for modern teams.";
System.out.println(s);
String result = "";
for (char c : s.toCharArray()) {
if (c != ' ') {
result += c;
}
}
System.out.println(result);
}
@Test
public void ex09() {
String s1 = "antop";
String s2 = "antop";
String s3 = new String("antop");
System.out.println(s1 == s2);
System.out.println(s1.equals(s2));
System.out.println(s1 == s3);
System.out.println(s1.equals(s3));
}
@Test
public void ex10() {
Random random = new Random();
// long
long n = random.nextLong();
// to 36
String conv = Long.toString(n, 36);
System.out.println(n + " (16) to " + conv + " (36)");
}
@Test
public void ex11() {
// 문ìì´
String word = "Java⢠ìì ì ëì½ë를 ì²ë¦¬í©ìë¤. Let's go!";
System.out.println("string = " + word);
// char[] ë¡ ë³í
char[] chars = word.toCharArray();
System.out.println(Arrays.toString(chars));
// ìì¤í¤ ì½ë를 ì ì¸íê³ 16ì§ì ì ëì½ëë¡ ë³í
String[] unicode = new String[chars.length];
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
String s = String.valueOf(c);
unicode[i] = c > 0 && c <= 127 ? s : String.format("\\u%04x", Integer.parseInt(Integer.toHexString(c), 16));
}
System.out.println(Arrays.toString(unicode));
}
@Test
public void ex13() {
// ììì 1ë¶í° 49ê¹ì§ ì«ì를 ì±ì´ë¤.
List> triangle = new ArrayList<>();
for (int i = 0; i < loop; i++) {
List