/*
  DO NOT MODIFY THIS FILE.
  See coreJava.code
 */


class A
{
  int x;
  long y;

  A(int x, long y) {
    this.x = x;
    this.y = y;
  }
}

public class coreJava 
{
  public static void p(String s)
  {
    System.out.println(s);
  }

  public static void p(boolean b)
  {
    System.out.println("" + b);
  }

  static A createA(int x, long y)
  {
    return new A(x, y);
  }

  public static void main(String[] args)
// -*- mode:java -*-

/*
  Test of core java features:
  - builtin types (integers, floats, chars)
  - ...

  Code must go inside the braces. 

  p(String s) is a method that calls System.out.println(s)

  A Java and Nice version will be generated automatically
  from this file, and their output will be compared.
 */

{
  //   STRINGS
  p("Hello, world!");
  p("String " + "\t\t" + "Z\70 \12X \101 concatenation"); // escapes, octal escape
  p("\u0041\u0042\u0043"); // "ABC" using unicode escapes

  //   CHARS

  p("" + 'A' + '\n' + '\u0201' + '\u4567' + "ABC".charAt(1));
  
  // unicode in identifiers
  int é\u0123 = 12;
  p("" + é\u0123);

  //   ARITHMETIC

  {
    // ints
    p("1 = " + 1);
    p("1+1 = " + (1+1));
  
    int i = 100;
    long j = 123;
    p("100 + 123 = " + (i+j));
    p("" + (i+(j-i)*(j+i*i)-4));

    p("" + ~i + ", " + ~j);

    p("" + 0x8000000000000000L);
    p("" + 0x7fffffffffffffffL);
    j = 456L + 0xABC;
    p("" + j);

    p("" + (i++));
    p("" + i);
    i = i++;
    i++;
    i--;
    p("" + i);
    j=--i;
    j=j;
    int k=++i;
    p("" + i + " " + j + " " + k);
    j = k = i;
    p("" + i + " " + j + " " + k);

    p("" + (2 & 3));
    k = 6;
    k &= 5;
    p("" + k);

    A a = createA(0, 0);

    p("x=" + a.x);
    a.x = 3;
    p("x=" + a.x);

    i = a.x++;
    j = a.x++;
    j = a.y--;
    p("x=" + a.x + ", i=" + i + ", j=" + j);
    short l = 200;
    j = l++;
    p("" + j + " " + l);

    p("" + (1 << 6));
    p("" + (i << i));
    p("" + (j << i));

    p("" + (165 >> 2));
    p("" + (l >> 1));
    p("" + (j >> 3));

    // floats
    float x = 0.1f;
    x += 0f;
    double y = 3.4;
    p("0.1 - 3.4 = " + (x-y));

    p("" + (i+(j-y)*x));

    y = -2.1;
    p("" + y);

    // bytes
    byte b = 127;
    b++;
    p("" + b);
  }

  {
    // Numeric comparison

    int i = 1;
    long l = 2;
    float f = 2.5f;
    double d = 2.7;

    p(i < i);
    p(i < l);
    p(i < f);
    p(i < d);

    p(i <= i);
    p(i <= l);
    p(i <= f);
    p(i <= d);

    p(i > i);
    p(i > l);
    p(i > f);
    p(i > d);

    p(i >= i);
    p(i >= l);
    p(i >= f);
    p(i >= d);

  }
    

  
  // booleans
  {
    p("" + ((false && true) | true));
    boolean b = false;
    if(b) p("A"); else p("B");
    p(!b ? "A" : (b ? "B" : "C"));
    if ('a' == 'b') p("Oops!1");
    boolean test = 'a' != 'a';
    if (test) p("Oops!2");
  }

  // String variables
  String constant = "Constant String";
  p(constant);

  //   LOOPS
  for (int i=0; i<6; ++i)
    {
      if (i == 4) continue;
      int j=i;
      while (j>0)
	{
	  p("i=" + i + ", j=" + j);
	  --j;
	  if (j == 1) break;
	}
    }

  while (true) break;

  // switch
  /*
  switch(3){
  case 0: p("0");
  case 3: p("3");
  case 4: p("4");
    break;
  case 5: p("5");
  default: p("default");
  }
  */

  //   ARRAYS
  
  int[] t;
  t = new int[2];
  t[0] = 1;
  t[1] = 2;
  for (int i = 0; i<t.length; i++)
    p("" + t[i]);

  // Local variables

  int var1 = 1, var2 = var1 + 1, var3 = var2 + 1;
  p("Local variables: " + var1 + var2 + var3);

  // Printing

  System.out.println("println");
  System.out.print("print");
  System.out.println();
  System.out.print(1);
  System.out.print('c');
  System.out.println(true);
  
  //   EXCEPTIONS

  try{
    try{
      return;
    }
    finally{
      p("Finally is executed if return is called from try");
    }
  }
  finally{
    p("Outer finally blocks must be executed too");

    try{
      try{
	if (false)
	  return;
      }
      finally{
	p("Finally is executed if return is called from try");
      }
      return;
    }
    finally{
      p("Outer finally blocks must be executed too");
    }

  }
}
}
