Search Header Logo

Code Mastery Challenge

Authored by Lakshmi Bollepalli

English

12th Grade

Used 1+ times

Code Mastery Challenge
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

15 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Debug the following code snippet: int x = 5; for(int i = 0; i < x; i++) { System.out.println(i); }

The loop will print numbers from 1 to 5

No issues found in the code snippet.

The loop will print numbers from 0 to 4

The loop will print numbers from 0 to 5

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Optimize the performance of the following code: for(int i = 0; i < 1000; i++) { System.out.println(i); }

Adding a sleep statement inside the loop

Using a LinkedList instead of StringBuilder

StringBuilder sb = new StringBuilder(); for(int i = 0; i < 1000; i++) { sb.append(i).append('\n'); } System.out.println(sb.toString());

Removing the loop and printing each number individually

3.

MULTIPLE CHOICE QUESTION

5 mins • 1 pt

Solve the real-world problem: Given an array of integers, find the maximum difference between any two elements.

The correct answer is to find the maximum difference between any two elements in the array of integers by subtracting the minimum value from the maximum value.

Sort the array in descending order

Find the average of the elements in the array

Calculate the sum of all elements in the array

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Debug the following code snippet: String str = 'Hello World'; System.out.println(str.substring(0, 5));

String str = 'Hello World'; System.out.println(str.substring(0, 6));

String str = 'Hello World'; System.out.println(str.substring(0, 5));

String str = "Hello World"; System.out.println(str.substring(0, 5));

String str = 'Hello World'; System.out.println(str.substring(1, 5));

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Optimize the performance of the following code: List numbers = new ArrayList<>(); for(int i = 0; i < 1000000; i++) { numbers.add(i); }

List numbers = new ArrayList<>(); for(int i = 0; i < 1000000; i++) { numbers.add(i); numbers.remove(0); }

List numbers = new ArrayList<>(); for(int i = 0; i < 1000000; i++) { numbers.add(0, i); }

List numbers = new ArrayList<>(1000000); for(int i = 0; i < 1000000; i++) { numbers.add(i); }

List numbers = new LinkedList<>(); for(int i = 0; i < 1000000; i++) { numbers.add(i); }

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Solve the real-world problem: Implement a function to check if a given string is a palindrome.

function checkPalindrome(str) { return str === str.split('').reverse().join(''); }

function isPalindrom(str) { return str === str.split('').reverse().join(''); }

function palindromeCheck(str) { return str === str.split('').reverse().join(''); }

function isPalindrome(str) { return str === str.split('').reverse().join(''); }

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Debug the following code snippet: int[] arr = {1, 2, 3, 4, 5}; for(int i = 0; i <= arr.length; i++) { System.out.println(arr[i]); }

int[] arr = {1, 2, 3, 4, 5}; for(int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }

int[] arr = {1, 2, 3, 4, 5}; for(int i = 0; i < arr.length - 1; i++) { System.out.println(arr[i]); }

int[] arr = {1, 2, 3, 4, 5}; for(int i = 1; i < arr.length; i++) { System.out.println(arr[i]); }

int[] arr = {1, 2, 3, 4, 5}; for(int i = 0; i < arr.length; i++) { System.out.println(arr[i]); }

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?