Skip to content

Instantly share code, notes, and snippets.

@OlgaKulikova
Created January 23, 2015 09:50
Show Gist options
  • Save OlgaKulikova/f88bfbcc683115b71d1c to your computer and use it in GitHub Desktop.
Save OlgaKulikova/f88bfbcc683115b71d1c to your computer and use it in GitHub Desktop.
Tests
public class Test1 {
static int x = 0;
public static void main(String[] args) {
beta();
}
public static void beta() {
int y = 1;
iter(y);
System.out.print(x + " ");
System.out.print(y);
}
public static void iter(int y) {
y++;
x++;
}
}
Варианты:
1. 1 1
2. 0 1
3. 1 2
4. 0 2
Аргументы в командной строке не заданы
public class Test2 {
public static void main(String[] args) {
System.out.println(args.length);
}
}
Варианты:
1. Не скомпилируется
2. NullPointerException
3. 0
4. no args
public class Test3 {
public static void main(String[] args) {
boolean b1 = false, b2 = false;
int x = 0;
if (!b1) {
if (!b2) {
b1 = true;
x++;
if (5 > 6) {
x +=10;
}
if (b2) {
x +=100;
}else if (b1 = b2) {
x++;
}else if (b1 | b2) {
x += 1000;
}
System.out.println("x = " + x);
}
}
}
Варианты:
1. 11
2. 1
3. 101
4. Не скомпилируется.
}
public class Test4 {
public static void main(String[] args) {
char c2 = '\u0057', c3 = 127;
c2 += 47;
System.out.println(c1 + c2 + c3);
}
}
Варианты:
1. 356
2. Какие-то символы
3. Не скомпилируется
4. 57 + 127 + 47
public class Test5 {
public static void main(String[] args) {
int a = 1, b = 1;
System.out.println("a + 1 = " + 4 / 2 == ("b + 1"));
}
}
Варианты:
1. false
2. true
3. a + 1 = false
4. a + 1 = true
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment