Title: OpTest.java
Course: CPS 261: Advanced Java Concepts ~ DL & MM MASTER

OpTest.java


import tools.*;
class OpTest
{
  public static void main (String[] args)
  {
    MyInput in= new MyInput();
    int x, y;
    for (;;)
    {
        P.println("Enter x");
        x = in.getInt();
        P.println("Enter y");
        y = in.getInt();

        process(x,y);
        P.println("*******************************************");
    }
  }
  static void process(int x, int y)
  {
    int value;
    boolean bvalue;

    P.bitPrint(x);
    P.println("   x="+x );

    P.bitPrint(y);
    P.println("   y="+y );

    value = x & y;
    P.bitPrint(value);
    P.println("   x & y");

    value = x | y;
    P.bitPrint(value);
    P.println("   x | y");


    value = x ^ y;
    P.bitPrint(value);
    P.println("   x ^ y");

    value = x << y;
    P.bitPrint(value);
    P.println("   x << y");

    value = x >> y;
    P.bitPrint(value);
    P.println("   x >> y");

    value = x >>> y;
    P.bitPrint(value);
    P.println("   x >>> y");

    value = ~x;
    P.bitPrint(value);
    P.println("   ~x");

    value = x + y;
    P.println("x+y=" +value);

    value = x - y;
    P.println("x-y=" +value);

    value = x * y;
    P.println("x*y=" +value);

    value = x/y;
    P.println("x/y=" +value);

    value = x % y;
    P.println("x%y=" +value);

    bvalue = x < y;
    P.println("x <  y=" + bvalue);

    bvalue = x <= y;
    P.println("x <= y=" + bvalue);

    bvalue = x > y;
    P.println("x >  y=" + bvalue);

    bvalue = x >= y;
    P.println("x >= y=" + bvalue);

    bvalue = x == y;
    P.println("x == y=" + bvalue);

    bvalue = x != y;
    P.println("x != y=" + bvalue);

    value =x;
    P.println("x++, x ="+ value++  +  ", " + value);

    value =x;
    P.println("++x, x ="+ ++value  +  ", " + value);

    value =x;
    P.println("x--, x ="+ value--  +  ", " + value);

    value =x;
    P.println("--x, x ="+ --value  +  ", " + value);
  }
}


Last Updated: September 2, 2002 4:26 PM