Font size
WorksheetsJava Array
Total questions: 21
Worksheet time: 16mins
int[] myArray = {11, 22, 33, 44, 55};
yang manakah antara berikut kod untuk mencetak panjang array ini?
System.out.println(int[].myArray.length());
System.out.println(myArray.length);
System.out.println(myArray.length());
System.out.println(int[].myArray.size());
String[] friends = {"John", "Mike", "Samantha", "Monica"};
which code is correct to print "Samantha" using array functionality?
System.out.println(friends[2]);
System.out.println(friends[3]);
System.out.println(friends["Samantha"]);
System.out.println(friends{2});
Select correct code to create an array of "double" datatype of length 5.
double arr = double[5];
double{} arr = new double{5};
double[5] arr = new double[];
double[] arr = new double[5];
Apakah kaitan antara panjang sesuatu array dan indeks terakhir array tersebut?
last-index is always 1 more than the length
last-index is 1 less than the length (but not always)
last-index is always 1 less than the length
last-index is always equal to the length
Kod untuk mengistiharkan array yang menyimpan markah(mark) untuk 20 orang pelajar.
double mark;
double [20] mark = new double;
double [ ] mark = new mark [20];
double [ ] mark = new double [20];
Kod untuk mengistihar array yang menyimpan nama 15 orang students.
String [ ] name = new String;
String [ ] name = new String [15];
name = new String [15];
String [15] name = new String [ ];
Java code to display the size of an array name studentname[ ].
System.out.println("The size is " + studentname[ index ]);
System.out.println("The size is " + studentname.length);
System.out.println("The size is " + length.length);
System.out.println("The size is " + studentname);
Kod Java untuk menginput nama ke dalam array studentname[ ].
Based on the code segment below:- identify the name of the array.
for(int j=0; j<balance.length; j++)
{
System.out.print("Enter amount: ");
.......
}
No answer.
temp[ ]
balance
balance [ i ]
Which of the following will create an out of bounds error? (select 2)
Which value is not valid as an index for the following array?
0
5
10
9
Java array indexes start at 0.
True
False
What is the value of nums[3]?
(a)
What is the index of the 12 in this array?
(a)
What is the value of nums[5] after this code is executed?
10
50
55
5
A Java array can hold multiple types of data.
True
False
What is the result of this code executing?
nums[1] dan nums[2] akan berakhir dgn nialai asal nums[2]
nums[1] dan nums[2] akan berakhir dengan nilai asal nums[1]
nums[2] dan nums[1] bertukar nilai.
tiada perubahan
For the array:
int stats[5];
Apakah julat index?
1-5
0-4
1-4
0-5
for(int i=0; i<10; i++)
numbers[i] = 2 * i + 1;
// Which index of the array holds the value of 7?
7
6
3
1
What is the error in the following code fragment?
double [] average = new double [20];
average[20] = 15.25;
A cast is required
Double not found
Array out of bounds error
Data not initialized
Predict the output?
public class Main {
public static void main(String args[]) {
int arr[] = {10, 20, 30, 40, 50};
for(int i=0; i < arr.length; i++)
{
System.out.print(" " + arr[i]);
}
}
}
10 20 30 40 50
Compiler Error
10 20 30 40
