enum INDEX{JEDEN,DWA,TRZY};
public void hello() {
int x[][] = new int[2][];
int x[0]={1,2}; //zonk :( compile error
int x[]={1,2,3};
int y= x[INDEX.DWA]; //zonk compile error!!!
}
- int a[]={1,2,}; //ok
- int a[]; a={1,2,3} //Compile error
enum INDEX{JEDEN,DWA,TRZY};
public void hello() {
int x[][] = new int[2][];
int x[0]={1,2}; //zonk :( compile error
int x[]={1,2,3};
int y= x[INDEX.DWA]; //zonk compile error!!!
}
@Test
public void swicz() {
//jako argument: byte, short, char, int i enum!
// NIE long ;(
//błąd nr 1
// wartość CASE jest większa niż typu !!!!
byte b = 10;
// switch(b){ case 150: break; }
//błąd nr 2
//zmienna jako CASEnie znana w czasie kompilacji
final int x = 7;
//sytuacja błędówa :D
final int y;
y = 7;
switch (y) {
case x: {
}
//! case y:{} // constant expr required!!!!!
}
//błąd nr 3 => powtarzajace się wartości case
// uwaga na obliecznia wartości case przez consty!
}
@Test
public void testDefaultInSwitch() {
/**
* WNOSIKI:
* 1) Jeśli istnieje case o wartości x to nei bedzie default
* 2) Jeśli nie istnieje case ... to bedzie default
* BEZ wezględu na miejsce!!!
*/
int x = 6;
switch (x) {
default: {
prn("Default");
break;
}
case 6: {
prn("6");
break;
}
}
/*WYNIK 6*/
/////////switch 2
x=5;
switch (x) {
default: {
prn("Default");
}
case 6: {
prn("6");
break;
}
}
/*WYNIK: Default 6*/
}
@Test
public void test1() {
//kwestia && i & w if
if(True("1") &&True("2") & True("3")){} // 1 2 3
if(False("1") &&True("2") & True("3")){} // 1 !!!!!!!!
if(True("1") &&False("2") & True("3")){} // 1 2 3
if(True("1") &&False("2") && True("3")){} // 1 2
if(False("1") & True("3")){} // 1 3
//kwestia || i |
if(True("1") || False("2")){}//1
if(True("1") | False("2")){}//1 2
if(False("1") ||False("2") && False("3")){} // 1 2
if(False("1") ||False("2") | False("3")){} // 1 2 2
}
public boolean True(String msg ){
System.out.println(msg);
return true;
}
public boolean False(String msg ){
System.out.println(msg);
return false;
}
Following code fragment is given (Java 5): 1: class Human {Which of the following methods would compile if inserted at line 8 | | ||||||||||||||||||||
| |||||||||||||||||||||
| | A try block can be followed either by a catch block or a finally block, or both. | |
| | | A catch block must always be associated with a try block. |
| | | A finally block can never stand on its own (that is, without being associated with try block). |
if(20%4){} //zonk bo wynikiem jest int!!
String s = null; /* Nie bedzie NullPointerException!!!!!!!!!*/
String result = s != null && s.equals("test") ? "yes" : "no";
System.out.println(1+2+"sd");//3sd
System.out.println("_"+12+3); //_123
System.out.println("_"+(1+2+3)); //_6