Sheet 4-2
Sheet 4-2
Mcq
1. Which of these is an incorrect array declaration?
a) int arr[] = new int[5]
b) int [] arr = new int[5]
c) int arr[] = new int[5]
d) int arr[] = int [5] new
a) 0 2 4 6 8
b) 1 3 5 7 9
c) 0 1 2 3 4 5 6 7 8 9
d) 1 2 3 4 5 6 7 8 9 10
3. What will be the output of the following Java code?
a) 3
b) 0
c) 6
d) 1
a) [1, 9, 10]
b) [1, 10, 9]
c) [10, 1, 9]
d) None of the above
problem solving:
5- Write a Java program to find common elements between two arrays (string values).
6- Guess character
Write a program that creates an ArrayList of characters (choose as many and which you
like).
Now let the user enter characters to guess which characters are in the arraylist.
Let him continue guessing until he has entered all characters in the list
(bonus point: print at the end how many guesses he took).
7- Daily Temperature Tracker Imagine you work for a weather station, and you need to
analyze the daily temperatures for the past week. The task is to find out which day(s)
recorded the highest and lowest temperatures. You'll be using a one-dimensional array
to store and process this data.
8- Calculate the Average of an Array of Numbers You have a list of numbers representing
the scores of students in a test. You need to calculate the average score.
9- Remove Duplicates from an Array You have a list of integers, and you need to remove
the duplicates from the array, leaving only unique elements.
10- Sum of Even Numbers in an Array You have a list of integers, and you need to find the
sum of all the even numbers in the array.