Search Header Logo

Java Array Quiz

Authored by simamkele yawa

Mathematics

University

Used 3+ times

Java Array Quiz
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

48 questions

Show all answers

1.

MULTIPLE SELECT QUESTION

5 mins • 2 pts

Which of the following Array declaration statement is illegal?

int [ ] a [ ] = new int [4] [4];

int a[ ][ ] = new int [4] [4];

int a[ ] [ ] = new int [ ] [4];

int [ ] a [ ] = new int [4] [ ];

2.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

What will happen if you try to compile and run the following code ? public class Test { public static void main (String args[]) { int[] arr = new int [] {1,2,3}; System.out.println(arr[1]); } }

1

Error: arr is referenced before it is initialized

2

Error: size of array must be defined

3.

MULTIPLE CHOICE QUESTION

1 min • 1 pt

In the given Array declaration, which expression returns the output as 5? int [] arr = { 23, 5, 78, 34, 2};

arr.length()

arr[].length()

arr[].length

arr.length

4.

MULTIPLE CHOICE QUESTION

5 mins • 3 pts

What will be the output upon the execution of the following code ? public class Test { public static void main(String[] args) { int j = 5; for (int i = 0; i< j; i++) { if ( i <= j-- ) System.out.print( (i*j) + " "); } } }

0 3 2

1 2 3

0 3 4

1 4 2

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which declaration of the main() method is valid ?

public void main( String args [] )

public void static main( String args [] )

final public static void main(String[] arr)

public static void main( String[] arr)

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

What will be the output of the following code ? public class Test { public static void main(String[] args) { double d = 100.04; float f = d; System.out.println("Float value "+f); } }

100.04

100.0

Compilation Error (lossy conversion from double to float)

100

7.

MULTIPLE CHOICE QUESTION

45 sec • 1 pt

Is it possible in Java to create arrays of length zero ?

Yes, you can create arrays of any type with length zero.

No, it is not possible to create arrays of length zero in Java.

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?