[JAVA] chatAt, SubString, Split 사용법
charAt 문자열 한글자씩 출력 String s = "무야호"; for(int i=0; i
- backend/자바
- · 2021. 5. 17.
Math.min 두수 중 더 작은수 출력 System.out.println(Math.min(10, 100)); 10 Math.max 두수 중 더 큰수 출력 System.out.println(Math.max(10, 100)); 100
String str = "Hello World"; char[] charArr = str.toCharArray(); [0] = H [1] = e [2] = l [3] = l [4] = o [5] = " " [6] = "W" [7] = "o" [8] = "r" [9] = "l" [10] = "d"
GCD 최대공약수 int a= 10; int b = 2; BigInteger b1 = BigInteger.valueOf(a); BigInteger b2 = BigInteger.valueOf(b); BigInteger gcd = b1.gcd(b2); System.out.println(gcd.intValue()); 2 LCD 최소공배수 public static int lcm(int x, int y) { //0이 아닌 두 수의 곱 / 두 수의 최대공약수 return (x * y) / gcd(x, y); } private static int gcd(int a, int b) { if(b == 0) { return a; } return gcd(b, a % b); } System.out.println(lcm(a, b..
charAt 문자열 한글자씩 출력 String s = "무야호"; for(int i=0; i
String 배열 선언 String[] array1 = new String[] {"1"}; String[][] array2 = new String[][] {{"1", "2"}, {"3", "4"}}; [1] [[1, 2], [3, 4]] Int 배열 선언 int[] iarray1 = new int[] {1}; int[][] iArray2 = new int[][] {{1, 2}, {3, 4}}; [1] [[1, 2], [3, 4]]
문자열 특정 문자열 있는지 체크 (contains) String txt = "무야호" ; if(txt.contains("무야")) { System.out.println("문자열 있음!"); } else { System.out.println("문자열 없음!"); } 특정 문자열 있는지 체크 (indexOf) String txt = "무야호" ; if(txt.indexOf("무야") > -1) { System.out.println("문자열 있음!"); } else { System.out.println("문자열 없음!"); } 특정 문자열 있는지 체크 (matches) String txt = "무야호" ; if(txt.matches(".*무야.*")) { System.out.println("문자열 있음!");..