자바 디지털 처리 클래스 상용 방법 집합

14275 단어 수필
오늘 은 자바 의 디지털 처리 류 와 관련 된 내용 을 배 웠 습 니 다. 그 중에서 흔히 볼 수 있 는 방법 이 많 습 니 다. 이 를 정리 하여 기억 과 조회 에 편리 합 니 다. 디지털 포맷 1. 자바. text. DecimalFormat 의 format () 과 apply Format () 방법 으로 각각 두 가지 포맷 디지털 방법 이 있 습 니 다. 첫 번 째: 대상 을 예화 할 때 디지털 포맷 템 플 릿 을 직접 설정 합 니 다.
DecimalFormat myFormat=new DecimalFormat(String pattern);
String output=myFormat.format(double value);

두 번 째: 대상 을 예 로 들 고 apply Pattern () 으로 디지털 형식 템 플 릿 을 설정 합 니 다.
DecimalFormat myFormat=new DecimalFormat();
myFormat.applyPattern(String pattern);
String output=myFormat.format(double value);

2. 숫자 그룹 크기 를 setGroupingSize () 로 설정 합 니 다.그룹 setGroupingUsed () 를 지원 할 지 설정 합 니 다.
2. 수학 연산 1. 삼각함수 방법
System.out.println("90     :"+Math.sin(Math.PI/2));
System.out.println("0     :"+Math.cos(0));
System.out.println("60     :"+Math.tan(Math.PI/3));
System.out.println("2     2      :"+Math.acos(Math.sqrt(2)/2));
System.out.println("2     2      :"+Math.asin(Math.sqrt(2)/2));
System.out.println("1     :"+Math.atan(1));
System.out.println("120°    "+Math.toRadians(120));
System.out.println("π    :"+Math.toDegrees(Math.PI));

2. 지수 함수 방법
System.out.println("e    :"+Math.exp(2));
System.out.println(" e   2   "+Math.log(2));
System.out.println(" 10   2    :"+Math.log10(2));
System.out.println("4     :"+Math.sqrt(4));
System.out.println("8     :"+Math.cbrt(8));
System.out.println("2 2   :"+Math.pow(2, 2));

3. 정수 방법
System.out.println("  ceil()    :"+Math.ceil(5.2));
System.out.println("  floor()    :"+Math.floor(2.5));
System.out.println("  rint()    :"+Math.rint(2.7));
System.out.println("  rint()    :"+Math.rint(2.5));
System.out.println("  round()    :"+Math.round(3.4f));
System.out.println("  round()    :"+Math.round(2.5));
System.out.println("4.2 8.5     :"+Math.max(4.2, 8.5));
System.out.println("4.4 4      :"+Math.min(4.4, 4));
System.out.println("-7    :"+Math.abs(-7))    

3. 난수 1. Math. random () 방법 은 0.0 ~ 1.0 사이 의 난수 에서 발생 하고 얻 은 x 는 0.0 < = x < 1.0 을 만족시킨다.
int s=(int)num1+(int)(Math.random()*(num2-num1));  //  num1 num2       

2. Random 클래스
Random r=new Random();
System.out.println("        :"+r.nextInt());
System.out.println("      0   n     :"+r.nextInt(5));
System.out.println("          :"+r.nextLong());
System.out.println("      boolean :"+r.nextBoolean());
System.out.println("          :"+r.nextFloat());
System.out.println("           :"+r.nextDouble());
System.out.println("                  :"+r.nextGaussian());

4. 큰 숫자 연산 1. BigInteger 류 는 모든 크기 의 정형 연산 을 지원 합 니 다.
BigInteger bigInstance=new BigInteger("4");
System.out.println("    :"+bigInstance.add(new BigInteger("2")));
System.out.println("    :"+bigInstance.subtract(new BigInteger("2")));
System.out.println("    :"+bigInstance.multiply(new BigInteger("2")));
System.out.println("    :"+bigInstance.divide(new BigInteger("2")));
System.out.println("    :"+bigInstance.remainder(new BigInteger("2")));
System.out.println("        (     ):"+bigInstance.divideAndRemainder
                (new BigInteger("2"))[1]);
System.out.println("   5    :"+bigInstance.pow(5));
System.out.println("    :"+bigInstance.negate());
System.out.println("     -5 (  5 ):"+bigInstance.shiftLeft(-5));
System.out.println("     5 :"+bigInstance.shiftRight(5));
System.out.println("    :"+bigInstance.and(new BigInteger("5")));
System.out.println("    :"+bigInstance.or(new BigInteger("5")));
System.out.println("       :"+bigInstance.compareTo(new BigInteger("5")));

2. BigDecimal 류 는 모든 정밀도 의 정수 연산 을 지원 하 는 데 자주 사용 되 는 가산, 감, 곱 하기, 제 연산 이 있 습 니 다. BigInteger 와 유사 합 니 다. 다만 나 누 는 방법 이 다 릅 니 다. Public BigDecimal divisor (BigDecimal divisor, int scale, int rounding Mode) 방법 에서 세 개의 매개 변 수 는 각각 나 누 기, 업 체 의 소수점 후의 자릿수, 유사 처리 모델 을 나타 냅 니 다.

좋은 웹페이지 즐겨찾기