Powered By Blogger

Thursday, December 16, 2010

C.S Holiday Homework

Sir below is just the code (but not the algorithm) and it is only half done. I was not sure what the holiday hw meant, and you didn't give any example also sir. But then I tried researching and understanding something to a certain extent with the class notes and below is what I have been able to so far. Please check.

CODE:
class CalculatorOperations
{
public static void main (Strings [ ] args)
{
System.out.println (“Calculation Section with operations:”);
System.out.println (“Enter the two integers”);
int value1;
int value2;
void get data (int a; int b)
{
value1 = a;
value2 = b;
}

System.out.println (“Enter operation ( +  -  *  / ) :  ”);
char operator;
void get data (char o)
{
char operator = o;
}
int calculate result (    );
{
int result;

if (operator = “ + ”)
{
result = value1 + value2;
}

else if (operator = “ - ”)
{
result = value1 - value2;
}

else if (operator = “ * ”)
{
result = value1 * value2;
}

else if (operator = “ / ” && value2 != 0)
{
result = value1 / value2;
}

else
{
System.out.println (“unknown operator” + operator + “Please try again.”);
}                                                                            
System.out.println (“ The result is: ” +result);
}
}
}

1 comment:

  1. it is bit tough for u right now. just write like this.

    for power function
    public void pow()
    {
    int p=5, pow;
    pow=Math.pow.(p,3);
    System.out.println("the pow of p is"+pow);
    }

    ReplyDelete