Вы находитесь на странице: 1из 35

1. Ce extrage ?

public class Test {


public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};
int v = values[0][0];
for (int[] list : values)
for (int element : list)
if (v > element)
v = element;
System.out.print(v) }}

Raspuns :1

2. Ce extrage ?
public class Test {
public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1 }, {33, 6, 1, 2}};
for (int row = 0; row < values.length; row++) {
java.util.Arrays.sort(values[row]);
for (int column = 0; column < values[row].length; column++)
System.out.print(values[row][column] + " ");
System.out.println(); }}}

Raspuns : doua linii: 1 3 4 5 si 1 2 6 33


3. Ce extrage ?
public class Test {
public static void main(String[] args) {
int[][] matrix =
{{1, 2, 3, 4},
{4, 5, 6, 7},
{8, 9, 10, 11},
{12, 13, 14, 15}};
for (int i = 0; i < 4; i++)
System.out.print(matrix[i][1] + " "); }}

Raspuns : 2 5 9 13

4. Ce extrage codul ?
public class Test5 {
public static void main(String[] args) {
int[][] matrix =
{{1, 2, 3, 4},
{4, 5, 6, 7},
{8, 9, 10, 11},
{12, 13, 14, 15}};
for (int i = 0; i < 4; i++)
System.out.print(matrix[1][i] + " ");}}

Raspuns : 4 5 6 7

5. Fie metoda p() are urmatorul antet. Care return poate fi folosit in p()?
public static int[][] p()

Raspuns : return new int[][]{{1, 2, 3}, {2, 4, 5}};


6. Ce extrage codul ?
public class Test {
public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};
for (int row = 0; row < values.length; row++) {
System.out.print(m(values[row]) + " ")}}
public static int m(int[] list) {
int v = list[0];
for (int i = 1; i < list.length; i++)
if (v < list[i])
v = list[i];
return v;}}

Raspuns : 5 33

7. fie double[][][] x = new double[4][5][6]. Ce valoare are x.length, x[2].length


si x[0][0].length

Raspuns: a. 4, 5, si 6

8. Care instructiuni sunt corecte ?


Raspuns: char[][][] charArray = new char[2][2][];
char[][][] charArray = {{{'a', 'b'}, {'c', 'd'}, {'e', 'f'}}};

9. Ce extrage codul ?
public class Test {
public static void main(String[] args) {
int[][][] data = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}}};
System.out.print(data[1][0][0]);}}
Raspuns: 5
10.Ce extrage codul ?
public class Test {
public static void main(String[] args) {
int[][][] data = {{{1, 2}, {3, 4}},
{{5, 6}, {7, 8}}};
System.out.print(ttt(data[0]));}
public static int ttt(int[][] m) {
int v = m[0][0];
for (int i = 0; i < m.length; i++)
for (int j = 0; j < m[i].length; j++)
if (v < m[i][j])
v = m[i][j];
return v;}}

Raspuns : 4

11. Care instructiune este corecta ?


Raspuns : char[][] charArray = {{'a', 'b'}, {'c', 'd'}};

12. Fie double[][] x = new double[4][5], ce valoare au x.length si x[2].length ?


Raspuns : 4 and 5

13. Care este variabila din linia 1 coloana 1 a matricei a ?


Raspuns : a[0][0]

14. Cand creati un tablou folosind insructiunea de mai jos, valorile


elementelor automat sunt initializate cu 0
Raspuns YES

15. Cate elemenete sunt in tabloul matrix (int[][] matrix = new int[5][5]) ?
Raspuns 25
16. Analizati codul
public class Test {
public static void main(String[] args) {
boolean[][] x = new boolean[3][];
x[0] = new boolean[1]; x[1] = new boolean[2];
x[2] = new boolean[3];
System.out.println("x[2][2] is " + x[2][2]);}}
Raspuns: Programul lucreaza si extrage x[2][2] is false

17. Fie int[][] x = {{1, 2}, {3, 4}, {5, 6}}. Ce valoare au x.length si x[0].length ?
RASPUNS: 3SI2

18. Fie int[][] x = {{1, 2}, {3, 4, 5}, {5, 6, 5, 9}}. Ce valoare au x[0].length,
x[1].length, si x[2].length ?
Raspuns: 2,3,4

19. Ce extrage codul ?


public class Test {
public static void main(String[] args) {
int[][] values = {{3, 4, 5, 1}, {33, 6, 1, 2}};
int v = values[0][0];
for (int row = 0; row < values.length; row++)
for (int column = 0; column < values[row].length; column++)
if (v < values[row][column])
v = values[row][column];
System.out.print(v);}}
Raspuns 33
Care afirmatie este corecta ?
Select one:
a. try trebuie sa fie urmat de cel putin un catch sau un finally
b. try trebuie sa fie urmat de catch
c. try trebuie sa fie urmat de cel putin 2 blocuri catch

d. try trebuie sa fie urmat de finally


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: try trebuie sa fie urmat de cel putin un catch sau un
finally

Question 2
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care din urmatoarele e declaratie gresita ?


Select one:
a. catch-finally block
b. try-catch block
c. try-catch-finally block

d. try-finally block
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: catch-finally block

Question 3
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care exceptii nu pot fi ignorate la compilare ?


Select one:
a. Checked Exception
b. Runtime Exception
c. Uncompiled Exception

d. Error
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Checked Exception

Question 4
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care exceptii pot fi ignorate la compilare ?


Select one:
a. Runtime
b. Checked
c. nici una

d. ambele
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Runtime

Question 5
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care fragment este corect ?


Select one:
a. try { } finally { }
b. catch { }
c. finally { }

d. try { }
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: try { } finally { }

Question 6
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care nu este cuvant cheie pentru tratarea exceptiilor ?


Select one:
a. exception
b. finally
c. try
d. catch

e. throw
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: exception

Question 7
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Ce este o exceptie ?
Select one:
a. o clasa
b. o interfata
c. o clasa abstracta
d. altceva
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: o clasa

Question 8
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Ce extrage ?
try { x.doStuff(); } int y = 50; } catch(FooException fe) { }

Select one:
a. Eroare la compilare
b. Eroare la executie
c. Trece compilarea fara erori

d. Lipseste raspunsul corect


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Eroare la compilare

Question 9
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Ce este o exceptie checked ?


Select one:
a. Exceptie verificata de compilator
b. Exceptie verificata de JVM
c. Exceptie verificata de compilator si JVM

d. Lipseste raspunsul corect


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Exceptie verificata de compilator

Question 10
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care bloc este executat oricand, independent daca a fost aruncata o exceptie
sau nu ?
Select one:
a. finally
b. throws
c. catch

d. throw
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: finally

Question 11
Correct
Mark 10.00 out of 10.00

Flag question

Question text

In ce conditii nu se executa blocul finally ?


Select one:
a. Cand e apelata System.Exit(1)
b. Cand apare o exceptie Error
c. Cand este aruncata o Exception
d. Toate
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Cand e apelata System.Exit(1)

Question 12
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care clasa este cea mai inalta in ierarhia claselor Java ?


Select one:
a. java.lang.Object
b.
java.lang.Error
c.
java.lang.Throwable

d.

java.lang.Exception
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: java.lang.Object

Question 13
Correct
Mark 10.00 out of 10.00

Flag question

Question text

In ce pachet se afla exceptiile ?


Select one:
a. java.util
b. java.lang
c. java.io

d. java
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: java.util

Question 14
Correct
Mark 10.00 out of 10.00

Flag question

Question text

In ce versiune Java au fost introduse exceptiile ?


Select one:
a. java 1
b. java 2
c. java 3

d. java 4
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: java 1

Question 15
Correct
Mark 10.00 out of 10.00

Flag question

Question text

In ce versiune Java a fost introdusa sintaxa cu multe blocuri catch ?


Select one:
a. 8
b. 5
c. 6

d. 7
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: 8

Question 16
Correct
Mark 10.00 out of 10.00

Flag question

Question text

java.lang.NullPointerException este:
Select one:
a. Runtime Exception
b. Error
c. Compile time exception

d. nici una
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Runtime Exception

Question 17
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Parintele clasei Error este:


Select one:
a. Throwable
b. Object
c. Collections

d. Exception
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Throwable

Question 18
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Care cuvant cheie este folosit pentru a arunca explicit o exceptie ?


Select one:
a. throw
b. catch
c. throws

d. raise
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: throw

Question 19
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Exception si Error sunt subclase direct din:


Select one:
a. Throwable
b. BaseException
c. Object

d. RuntimeException
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Throwable

Question 20
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Crearea unei exceptii si tratarea ei in timpul executiei se numeste


Select one:
a. Throwing an exception (aruncarea unei exceptiei)
b. Exception handler (tratarea exceptiei)
c. Catch the exception (prinderea exceptiei)

d. Pass the exception (transmiterea exceptiei)


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: Throwing an exception (aruncarea unei exceptiei)

Question 21
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Ce este throws in tratarea exceptiilor ?


Select one:
a. programatorul nu trateaza exceptia
b. programatorul trateaza exceptia
c. exceptia este tratata de jvm

d. lipseste raspunsul corect


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: programatorul nu trateaza exceptia

Question 22
Correct
Mark 10.00 out of 10.00
Flag question

Question text

try cu finally fara catch pot declara o exceptie


Select one:
a. true

b. false
Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: true

Question 23
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Ce este o exceptie unchecked ?


Select one:
a. exceptie verificata de JVM
b.
exceptie verificata de compilator
c.
exceptie verificata de compilator si de JVM

d. Lipseste raspunsul corect


Feedback

Răspunsul dumneavoastră este corect.


The correct answer is: exceptie verificata de JVM

Question 24
Correct
Mark 10.00 out of 10.00
Flag question

Question text

Exceptiile pot fi prinse sau aruncate metodei apelante


Select one:
True

False
Feedback

The correct answer is 'True'.

Question 25
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Checked Exceptions includ toate subclasele Exception, inclusiv si clasele ce


extind RuntimeException
Select one:
True

False
Feedback

The correct answer is 'False'.

Question 26
Correct
Mark 10.00 out of 10.00

Flag question

Question text

finally va fi executat independent daca a fost aruncata o exceptie sau nu


Select one:
True

False
Feedback

The correct answer is 'True'.

Question 27
Correct
Mark 10.00 out of 10.00

Flag question

Question text

In Java sunt 2 categorii de exceptii: checked si unchecked


Select one:
True

False
Feedback

The correct answer is 'False'.

Question 28
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Exceptiile se afla in pachetul java.util


Select one:
True

False
Feedback

The correct answer is 'True'.

Question 29
Correct
Mark 10.00 out of 10.00
Flag question

Question text

Pot folosi mai multe blocuri try ?


Select one:
True

False
Feedback

The correct answer is 'True'.

Question 30
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Este posibila re-aruncarea exceptiilor


Select one:
True

False
Feedback

The correct answer is 'True'.

Question 31
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Instructiunile ce urmeaza dupa cuvantul throw nu se executa


Select one:
True
False
Feedback

The correct answer is 'True'.

Question 32
Correct
Mark 10.00 out of 10.00

Flag question

Question text

Daca arunci o exceptie in codul tau, atunci trebuie sa declari exceptia cu throws
in declaratia metodei
Select one:
True

False
Feedback

The correct answer is 'True'.

Fie s1 si s2 sunt doua string-uri. Care afirmatii sau expresii sunt gresite ?
a. s1 >= s2 b. int i = s1.length

Fie s1 si s2 sunt 2 stringuri. Care din urmatoarele nu este corect ?


a. String s3 = s1 - s2 b. boolean b = s1.compareTo(s2);

Ce returneaza "abc".compareTo("aba") ?
a. 2
Ce returneaza "AbA".compareToIgnoreCase("abC") ?
a. -2
Care returneaza true ?
a. "peter".equalsIgnoreCase("Peter") b. "peter".equalsIgnoreCase("peter")
Ce extrage codul ?
a. University
Ce returneaza apelul "SELECT".substring(0, 5)?
a. "SELEC"
Ce returneaza apelul "SELECT".substring(4, 4)
a. Un sir vid
Analizati codul
class Test {
public static void main(String[] args) {
String s;
System.out.println("s is " + s);
}
}
a. Eroare la compilare deoarece s nu este initializat dar este referit in println

Pentru a verifica daca stringul s incepe cu "Java" vom scrie


a. if (s.startsWith("Java")) ... b. if (s.indexOf("Java") == 0) ...

Fie s un sting cu valoarea "java". Ce valoare are x dupa executarea codului


char x = s.charAt(4);
a. Nimic, deoarece la executie vom acvea runtime error
StringIndexOutofBoundsException

Pentru a verifica daca stringul s se termina cu "Java" vom scrie


a. if (s.endsWith("Java")) ... b. if (s.substring(s.length() -
4).equals("Java")) ...
Care instructiune returenaza JAVA ?
a. "Java".toUpperCase()
Care instructiune returneaza un string dintr-un tablou de caractere a ?
a. new String(a)
Fie s este " abc ". Care metoda returneaza un string nou "abc" ?
a. s.trim()

Fie s este "ABCABC". Care metroda returneaza "aBCaBC" ?


a. s.replace('A', 'a') b. s.replace('A', 'a')

Fie s este "ABCABC". Care metora returneaza un tablou de caractere ?


a. s.toCharArray()
Care metoda returneaza un string ?
a. String.valueOf(123) b. String.valueOf(12.53)

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s = "Java";
StringBuilder buffer = new StringBuilder(s);
change(s);
System.out.println(s);
}

private static void change(String s) {


s = s + " and HTML";
}
}
a. Java
Ce extrage instructiunea System.out.println("Java is neat".replaceAll("is",
"AAA")); ?
a. Java AAA neat

Ce extrage codul ?
public static void main(String[] args) {
String[] tokens = "Welcome to Java".split("o");
for (int i = 0; i < tokens.length; i++) {
System.out.print(tokens[i] + " ");
}
}
a. Welc me t Java
Care instructiune este preferabila pentru a crea stringul "Welcome to Java" ?
a. String s = "Welcome to Java";
Ce extrage codul ?
System.out.print("Hi, ABC, good".matches("ABC ") + " ");
System.out.println("Hi, ABC, good".matches(".*ABC.*"));
a. false true

Ce extrage codul ?
System.out.print("A,B;C".replaceAll(",;", "#") + " ");
System.out.println("A,B;C".replaceAll("[,;]", "#"));
a. A,B;C A#B#C

Ce extrage codul ?
String[] tokens = "A,B;C;D".split("[,;]");
for (int i = 0; i < tokens.length; i++)
System.out.print(tokens[i] + " ");
a. A B C D
Care metoda nu este corecta in Character ?
a. isDigit() b. toUpperCase()

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = "Welcome to Java!";
String s2 = s1;

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
a. s1 and s2 reference to the same String object
Cum putem obtien cuvantul "abc" in metoda main() cu apelul
java Test "+" 3 "abc" 2 ?
a. args[2]

Ce extrage codul la comanda java Test 1 2 3 ?


public class Test {
public static void main(String[] args) {
for (int i = 0; i < args.length; i++) {
System.out.print(args[i] + " ");
}
}
}
a. 1 2 3

Care fragment identifica corect numarul de argumente transmise din linia de


comanda aplicatiei Java ?
a. int count = args.length;

Care instructiune creeaza corect 5 String-uri vide ?


a. String[] a = {"", "", "", "", ""};

Ce probleme (erori) are codul ?


public class Test {
public static void main(String argv[]) {
System.out.println("argv.length is " + argv.length);
}
}
a. daca rulati programul fara a transmite nici un argument, va
extrage argv.length is 0

Care antet este corect pentru metoda main() ?


a. public static void main(String[] args) b. public static void main(String
args[])
Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = "Welcome to Java!";
String s2 = "Welcome to Java!";

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
a. s1 and s2 reference to the same String object

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = new String("Welcome to Java!");
String s2 = new String("Welcome to Java!");

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
a. s1 and s2 reference to different String objects

Fie s1 si s2 doua stringuri. Care este rezultatul codului ?


s1.equals(s2) == s2.equals(s1)
a. true

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = new String("Welcome to Java!");
String s2 = new String("Welcome to Java!");

if (s1.equals(s2))
System.out.println("s1 and s2 have the same contents");
else
System.out.println("s1 and s2 have different contents");
}
}
a. s1 and s2 have the same contents
Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = new String("Welcome to Java!");
String s2 = s1.toUpperCase();

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else if (s1.equals(s2))
System.out.println("s1 and s2 have the same contents");
else
System.out.println("s1 and s2 have different contents");
}
}
a.
s1 and s2 have different contents

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
String s1 = new String("Welcome to Java");
String s2 = s1;

s1 += "and Welcome to HTML";

if (s1 == s2)
System.out.println("s1 and s2 reference to the same String object");
else
System.out.println("s1 and s2 reference to different String objects");
}
}
a. s1 and s2 reference to different String objects

Cum pot initializa un tablou de 2 caractere cu 'a' si 'b' ?

Select one or more:


a. char[] charArray = {'a', 'b'};
b.
char[] charArray = new char[]{'a', 'b'};

Ce extrage?
public class Test {
public static void main(String[] args) {
double[] x = new double[]{1, 2, 3};
System.out.println("Value is " + x[1]);
}
}
Select one:

a. Value is 2.0

Fie int[] t = {1, 2, 3, 4}. Ce este t.length?


Select one:

a. 4

Ce extrage codul ?
double[] myList = {1, 5, 5, 5, 5, 1};
double max = myList[0];
int indexOfMax = 0;
for (int i = 1; i < myList.length; i++) {
if (myList[i] > max) {
max = myList[i];
indexOfMax = i;
}
}
System.out.println(indexOfMax);
Select one:

a. 1

Analizati codul
public class Test {
public static void main(String[] args) {
int[] x = new int[5];
int i;
for (i = 0; i < x.length; i++)
x[i] = i;
System.out.println(x[i]);
}
}
Select one:

a. Eroare la executie deoarece ultima instructiune


provoaca ArrayIndexOutOfBoundsException
Analizati codul (ciclul for-each). Ce extrage ?
public class Test {
public static void main(String[] args) {
double[] x = {2.5, 3, 4};
for (double value: x)
System.out.print(value + " ");
}
}Select one:

a. 2.5 3.0 4.0

Ce extrage codul ?
int[] myList = {1, 2, 3, 4, 5, 6};

for (int i = myList.length - 2; i >= 0; i--) {


myList[i + 1] = myList[i];
}

for (int e: myList)


System.out.print(e + " ");
Select one:

a. 1 1 2 3 4 5

Ce extrage codul ?
public static void main(String[] args) {
int[] x = {120, 200, 016};
for (int i = 0; i < x.length; i++)
System.out.print(x[i] + " ");
}
}
Select one:

a. 120 200 14

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
int list[] = {1, 2, 3, 4, 5, 6};
for (int i = 1; i < list.length; i++)
list[i] = list[i - 1];

for (int i = 0; i < list.length; i++)


System.out.print(list[i] + " ");
}
}
Select one:

a. 1 1 1 1 1 1

Ce extrage codul ?
class Test {
public static void main(String[] args) {
int[] list1 = {1, 2, 3};
int[] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;

for (int i = 0; i < list2.length; i++)


System.out.print(list2[i] + " ");
}
}
Select one:

a. 0 1 2

Care este elementul al 3-lea ?


Select one:

a. a[2]

Ce extrage codul ?
class Test {
public static void main(String[] args) {
int[] list1 = {1, 2, 3};
int[] list2 = {1, 2, 3};
list2 = list1;
list1[0] = 0; list1[1] = 1; list2[2] = 2;

for (int i = 0; i < list1.length; i++)


System.out.print(list1[i] + " ");
}
}
Select one:
a. 0 1 2

Analizati codul
public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4};
int[] y = x;

x = new int[2];

for (int i = 0; i < y.length; i++)


System.out.print(y[i] + " ");
}
}
Select one:

a. 1 2 3 4

Analizati codul
public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4};
int[] y = x;

x = new int[2];

for (int i = 0; i < x.length; i++)


System.out.print(x[i] + " ");
}
}
Select one:

a. 0 0

Analizati codul
public class Test {
public static void main(String[] args) {
final int[] x = {1, 2, 3, 4};
int[] y = x;

x = new int[2];

for (int i = 0; i < y.length; i++)


System.out.print(y[i] + " ");
}
}
Select one:

a. Eroare la compilare in instructiunea x = new int[2], deoarece x este


final si nu poate fi schimbat.

Analizati codul
int[] list = new int[5];
list = new int[6];
Select one:

a. Se compileaza si lucreaza normal. Linia 2 atribuie un tablou nou


pentru list.

Analizati codul
public class Test {
public static void main(String[] args) {
int[] a = new int[4];
a[1] = 1;
a = new int[2];
System.out.println("a[1] is " + a[1]);
}
}
Select one:

a. a[1] is 0

Care metoda copiiaza sourceArray in targetArray ?


Select one:
a.
System.arraycopy(sourceArray, 0, targetArray, 0, sourceArray.length);

Ce primeste metoda cand ii transmitem un tablou ?


Select one:

a. referinta la tablou

Ce extrage codul ?
public class Test {
public static void main(String[] args) {
int[] x = {1, 2, 3, 4, 5};
increase(x);

int[] y = {1, 2, 3, 4, 5};


increase(y[0]);

System.out.println(x[0] + " " + y[0]);


}

public static void increase(int[] x) {


for (int i = 0; i < x.length; i++)
x[i]++;
}

public static void increase(int y) {


y++;
}
}
Select one:

a. 2 1
Codurile urmatoare produc acelasi rezultat ?
Program I:
public class Test {
public static void main(String[] args) {
int[] list = {1, 2, 3, 4, 5};
reverse(list);
for (int i = 0; i < list.length; i++)
System.out.print(list[i] + " ");
}

public static void reverse(int[] list) {


int[] newList = new int[list.length];

for (int i = 0; i < list.length; i++)


newList[i] = list[list.length - 1 - i];

list = newList;
}
}

Program II:
public class Test {
public static void main(String[] args) {
int[] oldList = {1, 2, 3, 4, 5};
reverse(oldList);
for (int i = 0; i < oldList.length; i++)
System.out.print(oldList[i] + " ");
}

public static void reverse(int[] list) {


int[] newList = new int[list.length];

for (int i = 0; i < list.length; i++)


newList[i] = list[list.length - 1 - i];

list = newList;
}
}
Select one:

a. Yes

Fie tabloul double[] list = {3.4, 2.0, 3.5, 5.5}. Ce valoare are list[1] ?
Select one:

a. 2.0

Analizati codul
public class Test {
public static void main(String[] args) {
int[] oldList = {1, 2, 3, 4, 5};
reverse(oldList);
for (int i = 0; i < oldList.length; i++)
System.out.print(oldList[i] + " ");
}

public static void reverse(int[] list) {


int[] newList = new int[list.length];

for (int i = 0; i < list.length; i++)


newList[i] = list[list.length - 1 - i];

list = newList;
}
}
Select one:

a. extrage 1 2 3 4 5

Analizati codul
public class Test1 {
public static void main(String[] args) {
xMethod(new double[]{3, 3});
xMethod(new double[5]);
xMethod(new double[3]{1, 2, 3});
}

public static void xMethod(double[] a) {


System.out.println(a.length);
}
}
Select one:

a. eroare la compilare deoarece xMethod(new double[3]{1, 2, 3}) este


gresit

Cand returnati un tablou din metoda, metoda returneaza


Select one:

a. referinta la tablou

Fie metoda p() are antetul public static int[] p(). Care return poate fi
folosit in p() ?
Select one:

a. return new int[]{1, 2, 3};

Care din urmatoarele nu este corect ?


Select one or more:
a. int[] a = new int(2);
b. int a = new int[2];

c. int a() = new int[2];


Fie int[] list1 = {3, 4, 1, 9, 13}, int[] list2 = {3, 4, 1, 9, 13}, si int[] list3 = {4, 3,
1, 9, 13}. Ce extrage codul ?
System.out.println(java.util.Arrays.equals(list1, list2)
+ " " + java.util.Arrays.equals(list1, list3));
Select one:

a. true false

Fie int[] scores = {3, 4, 1, 9, 13}, care instructiune va extrage toate


elemenele tabloului ?
Select one:

a. System.out.println(java.util.Arrays.toString(scores));
Fie tabloul array double[] list = {3.4, 2.0, 3.5, 5.5}. Care este cea mai
mare valoare a indicelui in tablou ?
Select one:

a. 3

Cate elemente sunt in tabloul array double[] list = new double[5] ?


Select one:

a. 5

Care este termenul corect pentru numbers[99] ?


Select one:

a. variabila indexata

Fie int i=5. Care din urmatoarele poate fi folosit ca indice pentru array
double[] t = new double[100] ?
Select one or more:
a. i

b. i+10

Analizati codul
public class Test {
public static void main(String[] args) {
int[] x = new int[3];
System.out.println("x[0] is " + x[0]);
}
}
Select one:

a. Programul lucreaza normal si extrage x[0] is 0.

Care instructiuni sunt corecte ?


Select one or more:

a. double d[] = new double[30];


b. int[] i = {3, 4, 3, 2};

Вам также может понравиться