본문 바로가기
Class/220728

Class 예제(1-2)

by pms93 2022. 7. 28.
package constructor;

import java.util.ArrayList;

public class Reverse {

	private int data, result;
	public Reverse() {}
	public Reverse(int data) {
		this.data = data;
	}
	
	public int getData() {
		return data;
	}

	public void setData(int data) {
		this.data = data;
	}

	public int getResult() {
		return result;
	}

	public void setResult(int result) {
		this.result = result;
	}
	
	public void reverseResult() {
		ArrayList<Integer> tmp = new ArrayList<Integer>();	
		
		while (this.data != 0) {			
			tmp.add(this.data % 10);
			this.data /= 10;
		}
		
		int powCnt = tmp.size() - 1;
		for(int cnt = 0; cnt < tmp.size(); cnt++) {
			this.result += tmp.get(cnt) * (Math.pow(10, powCnt));
			powCnt--;
		}
		
		System.out.println(result);
	}
}

'Class > 220728' 카테고리의 다른 글

Class 예제(1-1)  (0) 2022.07.28
Class_Inheritance(1-5)  (0) 2022.07.28
Class_Inheritance(1-4)  (0) 2022.07.28
Class_Inheritance(1-3)  (0) 2022.07.28
Class_Inheritance(1-2)  (0) 2022.07.28