Notice
                              
                          
                        
                          
                          
                            Recent Posts
                            
                        
                          
                          
                            Recent Comments
                            
                        
                          
                          
                            Link
                            
                        250x250
    
    
  | 일 | 월 | 화 | 수 | 목 | 금 | 토 | 
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | 3 | 4 | 5 | 6 | 7 | 8 | 
| 9 | 10 | 11 | 12 | 13 | 14 | 15 | 
| 16 | 17 | 18 | 19 | 20 | 21 | 22 | 
| 23 | 24 | 25 | 26 | 27 | 28 | 29 | 
| 30 | 
                            Tags
                            
                        
                          
                          - 스프링
- Spring
- 파이썬
- 판다스
- streamlit
- CSS
- 프로젝트
- gcp
- 자바스크립트
- kotlin
- javascript
- mlb stats api
- 오라클
- oracle
- 코틀린
- HTML
- Android
- pandas
- 시간
- 어플
- Python
- java
- MLB
- 자바
- 배포
- 안드로이드
- 앱
- JQuery
- 제이쿼리
- 기록
                            Archives
                            
                        
                          
                          - Today
- Total
develope_kkyu
[JAVA] 두 점 사이의 거리 구하기 본문
728x90
    
    
  MyPoint.java
public class MyPoint {
	public int x;
	public int y;
	
	MyPoint(int x, int y){
		this.x = x;
		this.y = y;
	}
	
	public double getDistance(int i, int j) {
		double dis;
		dis = Math.sqrt((this.x-i)*(this.x-i) + (this.y-j)*(this.y-j));
		return dis;
	}
}MyPointExam.java
public class MyPointExam {
	public static void main(String[] args) {
//		System.out.println(Math.sqrt(4));	// 2.0*2.0 == 4
//		System.out.println(Math.sqrt(9));	// 3.0*3.0 ==9
		MyPoint p = new MyPoint(1,1);
		
		double dis = p.getDistance(1, 5);
		
		System.out.printf("두 점 사이의 거리는 = %4.0f\n", dis);
		
	}
}--
두 점 사이의 거리는 = 4
728x90
    
    
  'JAVA > Java SE' 카테고리의 다른 글
| [JAVA] 증감 연산자 (0) | 2022.12.21 | 
|---|---|
| [JAVA] 카페 메뉴 작업 (0) | 2022.12.21 | 
| [JAVA] 최대, 최소, 합계 구하기(함수 이용) (0) | 2022.12.21 | 
| [JAVA] 홀수단 출력 (1) | 2022.12.21 | 
| [JAVA] 구구단 출력 (1) | 2022.12.21 | 
