Commits (44)
class new_object {
public static void main(String[] args){
new new_object();
new_object obj = new new_object();
}
}
\ No newline at end of file
}
class AttributeKill {
public A objectA;
public static void main(String[] args) {
/* create and construct object A*/
A objectA = new A();
objectA.init();
/* set object to null*/
objectA = null;
/* calling uninitiated attribute of null object*/
int a = objectA.atr;
}
}
class A {
public int atr;
/* pseudo constructor */
public void init() {
atr = 2;
}
}
\ No newline at end of file
class AttributeOrSystem {
/* public int System; // error: int cannot be dereferenced*/
public static void main(String[] args) {
A objA = new A();
objA.init();
System.out.println(objA.atr);
}
}
class A {
public int atr;
public void init () {
atr = 2;
}
}
/**
* TODO 2 testcases?
*/
class CompareClassAttributes {
public static void main(String[] args) {
A objectA = new A();
B objectB = new B();
objectA.init();
objectB.init();
int result;
boolean bigger;
bigger = objectA.atr > objectB.atr;
result = objectA.atr + objectB.atr;
}
}
class A {
public int atr;
public void init () {
atr = 2;
}
}
class B {
public int atr;
public void init () {
atr = 3;
}
}
\ No newline at end of file
/**
* Implementation of the sieve of Eratosthenes.
*
* Computes all prime numbers in the interval [2,n], where n is read from stdin.
* Note that System.in.read() returns the ASCII value of the character read!
*/
class Eratosthenes {
public int[] result;
public int count;
public void sieve(int max) {
boolean[] sieve = new boolean[max];
count = 0;
/* Initialize array. */
{
sieve[0] = false;
sieve[1] = false;
int i = 2;
while (i < max) {
sieve[i] = true;
i = i + 1;
}
}
/* Sieve of Eratosthenes algorithm. */
{
int prime = 2;
while (prime < max) {
if (sieve[prime]) {
count = count + 1;
/* Deliberately unoptimized (strength reduction is possible). */
int mult = prime;
while (prime * mult < max) {
sieve[prime * mult] = false;
mult = mult + 1;
}
}
prime = prime + 1;
}
}
result = new int[count];
{
int i = 0;
int j = 0;
while (i < max) {
if (sieve[i]) {
result[j] = i;
j = j + 1;
}
i = i + 1;
}
}
}
public static void main(String[] args) throws Exception {
Eratosthenes e = new Eratosthenes();
int num = System.in.read();
e.sieve(num);
{
int i = 0;
System.out.println(e.count);
while (i < e.count) {
System.out.println(e.result[i]);
i = i + 1;
}
}
}
}
class FloatArithmetic {
public int _2p8;
public int _2p11;
public int _2p16;
public int _2p23;
public int _2p24;
public int _int_min;
public int _f1_5;
public int _fNaN;
public int _seemlinglyArbitraryConstant;
public int _exponentBias;
public void init() {
_2p8 = 256;
_2p11 = 2048;
_2p16 = 65536;
_2p23 = 8388608;
_2p24 = 16777216;
_int_min = -2147483648;
_f1_5 = 1069547520;
_fNaN = -1;
_seemlinglyArbitraryConstant = 1597463007;
_exponentBias = 127;
}
public int buildFloat(int sign, int exponent, int mantissa) {
int result = exponent * _2p23 + mantissa;
if (sign == 1) {
result = negate(result);
}
return result;
}
public int negate(int x) {
return _int_min + x;
}
public int sign(int x) {
if (x >= 0) {
return 0;
} else {
return 1;
}
}
public int exponent(int x) {
if (x < 0) {
x = negate(x);
}
return x / _2p23 % _2p8;
}
public int mantissa(int x) {
if (x < 0) {
x = negate(x);
}
return x % _2p23;
}
public int div2(int x) {
int mantissa = mantissa(x);
int exponent = exponent(x);
if (exponent == 0) {
return 0;
} else {
return buildFloat(sign(x), exponent(x) - 1, mantissa(x));
}
}
public int add(int x, int y) {
int xm = mantissa(x);
int xe = exponent(x);
int xs = sign(x);
int ym = mantissa(y);
int ye = exponent(y);
int ys = sign(y);
int exponentDiff;
int exponent;
int mantissa;
int sign;
int lm;
int sm;
if (xe > ye) {
exponentDiff = xe - ye;
exponent = xe;
sign = xs;
lm = xm;
sm = ym;
} else {
exponentDiff = ye - xe;
exponent = ye;
lm = ym;
sm = xm;
if (xe < ye || xm < ym) {
sign = ys;
} else {
sign = xs;
}
}
lm = lm + _2p23;
sm = sm + _2p23;
while (exponentDiff > 0) {
sm = sm / 2;
exponentDiff = exponentDiff - 1;
}
if (xs == ys) {
mantissa = lm + sm;
} else {
mantissa = lm - sm;
}
if (mantissa / _2p24 == 1) {
mantissa = mantissa / 2;
mantissa = mantissa % _2p23;
exponent = exponent + 1;
} else {
mantissa = mantissa % _2p23;
}
return buildFloat(sign, exponent, mantissa);
}
public int square(int x) {
return mult(x, x);
}
public int mult(int x, int y) {
int xm = mantissa(x);
int xe = exponent(x);
int xs = sign(x);
int ym = mantissa(y);
int ye = exponent(y);
int ys = sign(y);
xm = xm + _2p23;
ym = ym + _2p23;
int xm_lo = xm % _2p11;
int ym_lo = ym % _2p11;
int xm_hi = xm / _2p11;
int ym_hi = ym / _2p11;
int mantissa_lo = xm * ym;
int mantissa_hi = xm_hi * ym_hi
+ xm_hi * ym_lo / _2p11
+ xm_lo * ym_hi / _2p11
+ (xm_lo * ym_hi + xm_lo * ym_hi + mantissa_lo / _2p11) / _2p11;
int exponent = xe + ye - _exponentBias;
int mantissa = mantissa_hi / 2;
if (mantissa / _2p24 == 1) {
mantissa = mantissa / 2;
mantissa = mantissa % _2p23;
exponent = exponent + 1;
} else {
mantissa = mantissa % _2p23;
}
return buildFloat((xs + ys) % 2, exponent, mantissa);
}
public int invSqrt(int num) {
if (num <= 0) {
return _fNaN;
}
int x2 = div2(num);
int y = _seemlinglyArbitraryConstant - num / 2;
y = mult(y, add(_f1_5, negate(mult(x2, square(y)))));
return y;
}
public static void main(String[] args) {
FloatArithmetic ca = new FloatArithmetic();
ca.init();
/*System.out.println(Float.intBitsToFloat(ca.add(1036831949, 1069547520))); // 0.1 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1065353216, 1069547520))); // 1.0 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1069547520, 1069547520))); // 1.5 + 1.5
System.out.println(Float.intBitsToFloat(ca.add(1073741824, 1069547520))); // 2.0 + 1.5
System.out.println();
System.out.println(Float.intBitsToFloat(ca.mult(1036831949, 1069547520))); // 0.1 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1065353216, 1069547520))); // 1.0 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1069547520, 1069547520))); // 1.5 * 1.5
System.out.println(Float.intBitsToFloat(ca.mult(1073741824, 1069547520))); // 2.0 * 1.5
System.out.println();
System.out.println(Float.intBitsToFloat(ca.invSqrt(1036831949))); // 1 / sqrt(0.1)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1065353216))); // 1 / sqrt(1.0)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1069547520))); // 1 / sqrt(1.5)
System.out.println(Float.intBitsToFloat(ca.invSqrt(1073741824))); // 1 / sqrt(2.0)*/
}
}
class LocalInitClass {
public static void main(String[] args) {
Test test = new Test();
/*giving the localVariable itself as parameter*/
test.algorithm(test);
}
}
class Test{
public Test testlocalVar;
public int algorithm(Test Test) {
testlocalVar = Test;
return 0;
}
}
\ No newline at end of file
/**
* Check if attribute can be initializsed with expression and then used for initializing other local variable
*/
class LocalVariableOverwriteAttribute {
public int varInt;
public void algorithm() {
varInt = 1 + 2;
int localVar = varInt;
System.out.println(localVar);
}
public static void main(String[] args) {
LocalVariableOverwriteAttribute test = new LocalVariableOverwriteAttribute();
test.algorithm();
}
}
\ No newline at end of file
class NoConstructedObjectCall {
public static void main(String[] args) {}
public void test() {
int b = objA.atr;
return;
}
}
class A {
public int atr;
public void init () {
atr = 2;
}
}
/**
* Call without Parameter to Method
* error: variable a is already defined in method test(int)
*/
class NoParameterDeclaration {
public int a;
public static void main(String[] args) {
NoParameterDeclaration testObj = new NoParameterDeclaration();
/*there is no parameter given here*/
testObj.test();
}
public void test(int i) {
int a = i;
}
}
class OverwriteAttributeWithUndeclaredVariable {
public String a;
public static void main(String[] args) {
OverwriteAttributeWithUndeclaredVariable obj = new OverwriteAttributeWithUndeclaredVariable();
obj.test();
}
public void test() {
/*should break here because of undeclared unknown variable*/
a = i;
}
}
class String {
}
/**
* Tests a lot of double naming
*/
class RightVariable {
public static void main(String[] args) {
}
public int Test;
public Test Test(Test Test) {
return Test;
}
public void testMethod() {
/*init Test object*/
Test test = new Test();
/*call and init attribute of class*/
test.Test = 3;
/*init RightVariable Attribute*/
Test = 5;
/*Overwrite test attribute with RightVariable class Attribute*/
test.Test = Test;
/*call class RightVariable method Test, with the test object declared in the current method*/
Test(test);
/*Overwrite class Test with with local method Test, with itself given as an obj ref..*/
test = Test(test);
}
}
class Test {
public int Test;
public void Test() {
}
}
\ No newline at end of file
/**
* Declare void as type for variale
* java:6: error: '(' expected -> for method
*/
class VoidAttribute {
public void a;
public static void main(String[] args) {}
}
class WrongReturnTypeVoid {
public static void main(String[] args) {}
public void a() {
/*should not allow return of integer*/
return 5;
}
}
class ArrayAccess {
public static void main(String[] args) {
int[] array = new int[3];
array[2] = 42;
int elem = array[2];
}
}
class ArrayAccessNotAStatement {
public int[] test;
public static void main(String[] args) {
}
public void foo() {
test[1];
}
}
class Test {
public static void main(String[] args) {
int foo = 0;
int bar = foo[12];
}
}
class Main {
public static void main(String[] arguments) {
Main main = new Main();
main.getArray()[0] = 1;
new Main().getArray()[0] = 2;
}
public int[] getArray() {
int[] result = new int[1];
result[0] = 42;
return result;
}
}
class ArrayLength {
public static void main(String[] args) {
int[] x = new int[23];
/* use of .length is invalid in MiniJava */
int y = x.length;
}
}
class ArrayOutOfBounds {
public static void main(String[] args) {
int[] x = new int[5];
/* This is a runtime error, the compiler shouldn't care */
int y = x[10];
}
}
class Summator {
public int sum(int[] array, int len) {
int sum = 0;
int i = 0;
while(i < len) {
sum = sum + array[i];
i = i + 1;
}
return sum;
}
public static void main(String[] args) {
Summator acc = new Summator();
int arrayLen = System.in.read();
int[] array = new int[arrayLen];
int i = 0;
while(i < arrayLen) {
array[i] = System.in.read();
i = i + 1;
}
int arraySum = acc.sum(array, arrayLen);
System.out.println(arraySum);
}
}
class Arr {
public static void main(String[] args) {
int[] x = null;
}
}
class Main {
public static void main(String[] arguments) {
System = null;
}
}
class Main {
public static void main(String[] arguments) {
System.out = null;
}
}
class Test {
public static void main(String[] args) {
}
public void foo(int a) {
a = 5;
}
}
class IntBool {
public static void main(String[] args) {
boolean x = 0;
}
}
class BooleanConstantNotAStatement {
public static void main(String[] args) {
true;
}
}
class Schuessel {
public static void main(String[] Schluessel) {
Schuessel schluessel = (new Schuessel()) + (new Schuessel());
}
}
\ No newline at end of file
class Glas {
public static void main(String[] glas) {
boolean ledlichtchen = (new Glas()) < (new Glas());
}
}
\ No newline at end of file
class Test {
public static void main(String[] args) {
Test test = new Test();
if (null == test) {
return;
}
}
}
class Test {
public static void main(String[] args) {
Test test = new Test();
if (test == null) {
return;
}
}
}
class Test {
public static void main(String[] args) {
}
public void test() {
Foo foo = new Foo();
foo.bar(this);
}
}
class Foo {
public void bar(Test test) {
test.test();
}
}
class Prog1 {
public static void main(String[] args) {
(new Prog1()).test();
}
public boolean test() {
int a = 10;
if(a > 0) if(a > 5) if(a > 10) return true; else return false; else return true;
return false;
}
}
class DuplicateClass {
public static void main(String[] args) {}
}
class DuplicateClass {}
class DuplicateField {
public int duplicate;
public int duplicate;
public static void main(String[] args) {}
}
class Foo {
public int bar(int x) {
;;;;
return x;
}
public static void main(String[] args) {
Foo foo = new Foo();
foo.bar(0);
}
}
class EmptyWhile {
public static void main(String[] args) {
while(true);
}
}
class Arrays {
public int[] x;
public int[][] y;
public static void main(String[] args) {
eq();
}
public boolean eq() {
return x == y;
}
}
class A {}
class B {}
class AB {
public static void main(String[] agrs) {
eq(new A(), new B());
}
public boolean eq(A a, B b) {
return a == b;
}
}
class ExprStmt {
public int foo() {}
public static void main(String[] args) {
foo() + foo();
}
}
class FieldAccessStatic {
public int nonStatic;
public static void main(String[] args) {
nonStatic = 42;
}
}
class FieldAccessNotAStatement {
public int test;
public static void main(String[] args) {
test;
}
}
class FieldAccess {
public int field;
public static void main(String[] args) {
new FieldAccess().accessField();
}
public void accessField() {
int i = FieldAccess.field;
}
}
class Main {
public static void main(String[] arguments) {
Main main = new Main();
main.getX().x = null;
new Main().getX().x = null;
}
public X getX() {
return new X();
}
}
class X {
public X x;
}
class C1 {
public int x;
}
class C2 {
public C1 x;
}
class TypeError {
public static void main(String[] args) {
boolean b;
C2 obj = new C2();
b = obj.x.x;
}
}
class FieldAccessWithoutThis {
public static void main(String[] args) {
new FieldAccessWithoutThis().test();
}
public int field;
public void test() {
field = 10;
}
}
class FieldShadowing {
public int x;
public static void main(String[] args) {}
public void test() {
int x = 42;
this.x = x;
}
}
class IfElseTypeMismatch {
public static void main(String[] args) {
foo(true);
}
public int foo(boolean b) {
if (b) {
return 42;
} else {
return false;
}
}
}
class Test {
public static void main(String[] args) {
foo();
}
public void foo() {
}
}
class IllegalThisInStaticMethod {
public static void main(String[] args) {
IllegalThisInStaticMethod a = this;
}
}
class IntBool {
public static void main(String[] args) {
int x = false;
}
}
class IntegerConstantNotAStatement {
public static void main(String[] args) {
1;
}
}
class IntegerTooLarge {
public static void main(String[] args) {
int large = 100000000000;
}
}
class MismatchingTypeComparison {
public static void main(String[] args) {
boolean x = false;
boolean y = true;
boolean a;
a = x < y;
a = x <= y;
a = x > y;
a = x >= y;
}
}
class InvalidAssignToMainParameter {
public static void main(String[] test) {
test = new String[5];
}
}
class String {
}
class InvalidUnreachableCodeIsInvalid {
public static void main(String[] args) {
int x = 5;
return;
/* Unreachable code should still be checked */
boolean b = x;
}
}
class Test {
public static void main(String[] args) {
if (1234) {
return;
}
}
}
class Test {
public static void main(String[] args) {
while (1234) {
return;
}
}
}
class InvalidNullInteger {
public static void main(String[] args) {
int notNull = null;
}
}
class Test {
public static void main(String[] args) {
Test test = new Test();
if (test) {
return;
}
}
}
class Test {
public static void main(String[] args) {
Test test = new Test();
while (test) {
return;
}
}
}
class Test {
public static void main(String[] args) {
new Test().foo();
}
public void foo() {
this = new Test();
}
}
class ClassWithNonstaticMain {
/* String is a valid type */
public void main() { }
public void foo() {
main();
}
}
class ClassWithStaticVoidMainStringArgs {
public static void main(String[] args) {
ClassWithNonstaticMain x = new ClassWithNonstaticMain();
x.main();
}
}
class Test {
public static void main(String[] args) {
int test = !1;
}
}
class IKEA {
public static void main(String[] baum) {
int a = 2;
int b = 5;
int c;
a = b;
a+(b) = c;
}
}
\ No newline at end of file
class IKEA {
public static void main(String[] baum) {
boolean a = true;
boolean c;
!a = c;
}
}
\ No newline at end of file