✨
Java
  • 자바의 역사
  • Ch1
    • Before Start Java
      • History of Java
      • Feature of Java
      • API Documentation
      • Hello World!
      • eclipse shortcut
      • Eclipse IDE
      • GitHub to eclipse
  • Ch2
    • Variable
      • Variable
    • Variable Type
    • Character and String
    • Primitive type and range
    • printf and formatter
    • Scanner
    • Overflow of Int
    • Transition between different variable types
    • Object Array
  • CH3
    • Operator
  • CH4
    • 조건문과 반복문
    • if statement
    • switch
    • Math.random()
    • for statement
    • while statement
    • break, continue, named iterated statement
  • CH5
    • Array
    • 배열 활용
    • String Array
  • OOP
    • Intro
  • Class and Object
  • Make multiple Classes in one file
  • How to use Object
  • Object Array
  • Variable type according to declared location
  • Class Variable and Instance Variable
  • Method
  • Call Stack
  • Parameter
  • Static method(Class method) and Instance method
  • (Method)Overloading
  • Constructor
  • Constructor this()
  • Reference type variable "this"
  • Initialize variable
  • Inheritance
  • Composite
  • Single Inheritance, Object Class
  • (Method)Overriding
  • super, super()
  • package, class path
  • import, static import
  • modifier
  • access modifier
  • Encapsulation
  • Polymorphism
  • reference type transition
  • instanceof operator
  • Parameter polymorphism
  • Multiple object using one array
  • Abstract Class, Abstract Method
  • Creating Abstract Class
  • Interface
  • Interface Polymorphism
  • Interface Pros
  • Default method and static method
  • Inner Class
  • Anonymous Class
  • java.lang package and useful class
    • Object class
    • hashCode(), toString()
    • String class
    • StringBuffer class
    • StringBuilder class
    • Math class
    • Wrapper class
    • Number class
    • String to Number, String to Wrapper class
    • Auto-boxing and (auto)Unboxing
  • Collection Framework
    • Collections framework
    • List, Set, Map Interface
    • List의 removeAll() 과 clear() 비교
    • List Interface - ArrayList
    • How to view Java API source
    • List Interface - LinkedList
    • Stack and Queue
    • Iterator, ListIterator, Enumeration
    • Array
    • Comparator와 Comparable
    • Stack
    • String
    • String + char = String
    • String.toCharArray()
    • BufferedReader / BufferWriter
    • Scanner로 String 입력 - next( )와 nextLine( )
    • 공백없이 2차원배열 데이터 String으로 한번에 한줄씩 입력받기(문자/숫자)
    • 공백을 사이에 두고 빠른 2차원 배열 입출력
    • arr[index++]과 arr[index] index++의 차이
    • int와 long의 차이
    • Untitled
    • 타입 간의 변환
    • Array 와 ArrayList
    • valueOf()
    • Char
    • 변수, 객체 초기화(초기값 설정)
  • error troubleshooting
    • No enclosing instance of type
    • ASCII Code Table
    • java.lang.NumberFormatException
    • No enclosing instance..
  • reference
    • String을 생성하는 2가지 방법과 차이점
    • StackOverflowError(스택, 힙 메모리)
    • swtich-case 반복문
Powered by GitBook
On this page

Was this helpful?

  1. java.lang package and useful class

Math class

PreviousStringBuilder classNextWrapper class

Last updated 4 years ago

Was this helpful?

Math class : Group of static method that are related math.

Round(반올림하다) - round() : 소수점 아래 세 번째 자리에서 반올림. 1. 원래 값에 100을 곱한다. 90.7552 * 100 -> 9075.52 2. 위의 결과에 Math.round()를 사용한다. Math.round(9075.52) -> 9076 3. 위의 결과를 다시 100.0으로 나눈다. 9076 / . 00.0 -> 90.76, 9076 / 100 -> 90

  • Math class Method

Method

Description

Example

static double abs(double a)

static float abs(float a)

static int abs(int a)

static long abs(long a)

주어진 값의 절대값을 반환한다.

int i = Math.abs(-10);//10

double d = Math.abs(-10.0);//10.0

static double ceil(double a)

주어진 값을 올림하여 반환한다. 양수든 음수든 더 큰 쪽으로!

double d = Math.ceil(10.1);//11.0 double d2 = Math.ceil(-10.1);//-10.0 double d3 = Math.ceil(10.000015);//11.0

static double floor(double a)

주어진 값을 버림하여 반환한다. 양수든 음수든 더 작은 쪽으로!

double d = Math.floor(10.8);//10.0

double d2 = Math.floor(-10.8);//-11.0

static double max(double a, double b)

static float max(float a, float b)

static double max(int a, int b)

static double max(long a, long b)

static double min(double a, double b)

static float min(float a, float b)

static double min(int a, int b)

static double min(long a, long b)

주어진 두 값을 비교하여 큰 쪽/작은 쪽을 반환한다.

double d = Math.max(9.5, 9.50001);//d = 9.50001

int i = Math.max(0,-1);//0

double d2 = Math.min(9.5, 9.50001);//9.5

int i = Math.min(0,-1);//-1

static double random()

0.0~1.0 범위의 임의의 double 값을 반환한다.(1.0은 불포함)

double d = Math.random();

int i = (int)(Math.random()*10)+1;

0.0 <= d < 1.0

1 <= i < 11

static double rint(double a)

주어진 double값과 가장 가까운 정수값을 double형으로 반환한다. 단, 두 정수의 정 가운데 있는 값(1.5, 2.5, 3.5 등)은 짝수를 반환한다.=>round보다 오차가 적다.

double d = Math.rint(1.2);//1.0

double d2 = Math.rint(2.6);//3.0

double d3 = Math.rint(3.5);//4.0

double d4 = Math.rint(4.5);//4.0

static long round(double a)

static long round(float a)

소수점 첫째자리에서 반올림한 정수값(long)을 반환한다. 두 정수의 정가운데 있는 값은 항상 큰 정수를 반환한다.

rint()의 결과와 비교

long l = Math.round(1.2);//1

long l2 = Math.round(2.6);//3

long l3 = Math.round(3.5);//4

long l4 = Math.round(4.5);//5

double d = 90.7552;//90.7552

double d2 = Math.round(d*100)/100.0;//90.76

//9075.52 / 100.0 = 90.7552

//Math.round(90.7552) = 90.76.

round(), rint() result