라벨이 java인 게시물 표시

Thread 다루기. pool실행, 예외처리하기

http://palpit.tistory.com/732

자바 stack 사용하기

import java.util.Stack; public class StackExample {     public static void main(String[] args) {         Stack stack = new Stack<>();                  // 데이터 입력         stack.push(5);         stack.push(4);         stack.push(3);         stack.push(2);         stack.push(1);                  // 데이터 출력         System.out.println("마지막에 넣은 데이터부터 출력..");         System.out.println(stack.pop());         System.out.println(stack.pop());         System.out.println(stack.pop());         System.out.println(stack.pop()); ...

10진수<->2진수, 8진수, 16진수

자바 2진수, 8진수, 16진수 변환 시에는 Integer 클래스 API를 활용하면 편하다. (참고 :  https://docs.oracle.com/javase/8/docs/api/java/lang/Integer.html ) 10진수 -> 2진수, 8진수, 16진수 변환 1 2 3 4 5 6 7 8 int  num  =   77 ; String  a2  =  Integer.toBinaryString(num);   // 10진수 -> 2진수 String  a8 =  Integer.toOctalString(num);     // 10진수 -> 8진수 String  a16  =  Integer.toHexString(num);     // 10진수 -> 16진수 System . out . println ( "2 진수 : "   +  a2); System . out . println ( "8 진수 : "   +  a8); System . out . println ( "16 진수 : "   +  a16); cs 결과 1 2 3 2  진수 :  1001101 8  진수 :  115 16  진수 : 4d 2진수, 8진수, 16진수 -> 10진수로 변환 1 2 3 4 5 6 7 8 ...

MyLogger만들어서 print하기

public class MyLogger { private static boolean print = true; public static void Log(String str) { if(print) { System.out.println(str); } } public static void Log(String str, boolean flag) { if(print) { if(flag) System.out.println(str); } } }

동적프로그래밍(동전)

https://gist.github.com/developer-sdk/65e7f5491489a747040b1dd532cc7450

String format 사용하기

http://blog.devez.net/100

최소공배수, 최대공약수

// 최소 공배수 계산 메서드   // 최소공배수는 엄청나게 큰 숫자가 나올 수도 있기에   // long형으로 다루어야 합니다.   public static long lcm(long a, long b) {     int gcd_value = gcd((int)a, (int)b);     if (gcd_value == 0) return 0; // 인수가 둘다 0일 때의 에러 처리     return Math.abs( (a * b) / gcd_value );   }   // 최대 공약수 계산 함수; 최소 공배수 계산에 필요함   // 최대 공약수는 그리 큰 숫자가 나오지 않기에 int형으로   public static int gcd(int a, int b) {     while (b != 0) {       int temp = a % b;       a = b;       b = temp;     }     return Math.abs(a);   } ============================================================================= 재귀함수로 최대공약수 구하기 public  static int getGcd ( int x ,  int y )      {          if ( x  %  y  ==   0 )   return  y ;          return  getGcd ( y ,  x ...

자릿수반환하기

public static int[] getNumbers(int number) { /*String[] strArr = String.valueOf(number).split(""); int[] result = new int[strArr.length]; for (int i = 0; i < strArr.length; i++) { result[i] = Integer.valueOf(strArr[i]); } return result;*/ List list = new ArrayList (); while(number!= 0) { list.add(number%10); number = number/10; } Collections.reverse(list); int[] result = new int[list.size()]; for (int i = 0; i < list.size(); i++) { result[i] = list.get(i); } return result; }

pattern 정규화 표현식 완전정복

http://highcode.tistory.com/6

정규식 pattern으로 확장자 골라내기

public boolean test(String str) { String allowPattern = ".+\\.(gul|ppt|xls|hwp|jpg|zip|tif|alz|bmp|pdf)$"; boolean result = false;         Pattern p = Pattern.compile(allowPattern);         Matcher m = p.matcher(str);         result = m.matches(); return result; }

math 함수 쓰기

Math함수 abs(double a) : 절대값 ceil(double a) : 값올림 floor(double a) : 값내림 round(double a):반올림 max(double a, double a) : 큰쪽반환 mins(double a, double b): 작은값 pow(double a, double b) : a의 b제곱 random() : 0~1사이 값을 랜덤으로 반환

문자열 반복하기 String메소드이용

ava 1.5이상에서  repeated = new String(new char[n]).replace("\0", s);  이런 식으로 하시면 됩니다. n은 문자열 s를 몇번 반복할건지에 대한 변수입니다. repeated = new String(new char[n]).replace("\0", s);

String 함수

startWith:  문자열이 지정한 문자로 시작하는지 판단 같으면 true반환 아니면 false를 반환한다.(대소문자구별) ? 1 2 3 String str = "apple" ; boolean startsWith = str.startsWith( "a" ); System.out.println( "startsWith: " + startsWith); 결과값:true endWith: 문자열 마지막에 지정한 문자가 있는지를 판단후 있으면 true, 없으면 false를 반환한다.(대소문자구별) ? 1 2 3 String str = "test" ; boolean endsWith = str.endsWith( "t" ); System.out.println( "endsWith: " + endsWith); 결과값:true equals: 두개의 String에 값만을 비교해서 같으면 true, 다르면 false를 반환한다.(대소비교) ? 1 2 3 4 String str1 = "java" ; String str2 = "java" ; boolean equals = str1.equals(str2); System.out.println( "equals: " + equals); 결과값:true indexOf: 지정한 문자가 문자열에 몇번째에 있는지를 반환한다. ? 1 2 3 String str = "abcdef" ; int indexOf = str.indexOf( "d" ); System.out.println( "indexOf: " + indexOf); 결과값...