0% found this document useful (0 votes)
8 views4 pages

Sheet 4-2

Uploaded by

Ahmed Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Sheet 4-2

Uploaded by

Ahmed Mohamed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Sheet 4

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

2. What will be the output of the following Java code?

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

4. What is the index range for the elements of an array in Java?


a) 0 to length - 1
b) 1 to length
c) -1 to length - 1
d) 0 to length
5. What does this code output?

a) [1, 9, 10]
b) [1, 10, 9]
c) [10, 1, 9]
d) None of the above

problem solving:

1- Write a program to Sort Numeric Array In Ascending Order


Sample Output
Array = {23, 5, 67, 20, 3, 30, 79, 3, 70, 2}

2- Write a program to print sum values of an array


Sample Output
Array = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

3- Write a Java program to find the second largest element in an array.

4- Write a Java program to insert an element (specific position) into an array.

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.

You might also like