티스토리 뷰

IT Skills/Programming

java 계산기

E-yarn 2013. 4. 15. 03:01


package javaapplication7;



public class JavaApplication7 {


    public static void main(String[] args)  

    {

       Calculator cal=new Calculator(10);

       cal.Add(10);    

       cal.Subtract(3);   

       cal.Divide(4);     

       cal.Multiply(3);

       cal.Factorial();

       cal.Module(13);    

       cal.Power(3);

       System.out.println("계산 결과 : "+ cal.GetResult()); 

    

    }

  

    

    

     class Calculator 

        { 

        private long m_result;

        public Calculator(){}

        public Calculator(int n)

        {

            m_result=n;

        }

        

        public long Add(int n) 

        {

            m_result=m_result+n;

            return m_result;

        } 

       public long Subtract(int n) 

        {

            m_result=m_result-n;

            return m_result;

        } 

       public long Divide(int n) 

        {

            m_result=m_result/n;

            return m_result;

        } 

       public long Multiply(int n) 

        {

            m_result=m_result*n;

            return m_result;

        } 

       public long Factorial() 

        {

            for(int i=1;i<=m_result;i++)

                m_result*=i;

            return m_result;

        } 

       public long Module(int n) 

        {

            m_result=m_result%n;

            return m_result;

        } 

       public long Power(int n) 

        {

            for(int i=1;i<=n;i++)

            m_result*=m_result;

            return m_result;

        } 

       public long GetResult()

       {

           return m_result;

       }


        } 

}


 

댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2025/03   »
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 31
글 보관함