You are on page 1of 4

11th

March 2019

Program Kecemerlangan Akademik Sains Komputer


Semester 2, Sesi 2018/ 2019

1. (a) Declare a char array named code.


(b) Construct the new array named code with size 8.
(c) Declare and instantiate a String array called Word in one line.
(d) Declare and instantiate a String array called Word in two separate
lines.
(e) Declare, instantiate and initialize an int array named siblings to 1,2,3
and 4 in three different lines.
(f) Declare, instantiate and initialize an int array named siblings to 1,2,3
and 4 in one line.

2. (a) What is the output of the following code fragment?

int[] egArray = { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };

for ( int index= 0 ; index < 5 ; index++)

System.out.print( egArray[ index ] + " " );

(b) What is the output of the following code fragment?


int[] egArray = { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };

for ( int index= 0 ; index < egArray.length; index++)

System.out.print( egArray[ index ] + " " );


11th
March 2019

(c) What is the output of the following code fragment?

int[] egArray = { 2, 4, 6, 8, 10, 1, 3, 5, 7, 9 };

for ( int index= 0 ; index < egArray.length; index + 2)

System.out.print( egArray[ index ] + " " );

3. (a) Examine the following program fragment; What does the fragment write
to the monitor?

int[] array = { 1, 4, 3, 6, 8, 2, 5};


int what = array[0];

// scan the array


for ( int index=0; index < array.length; index++ )
{
if ( array[ index ] > what )
what = array[ index ];
}
System.out.println( what );
11th
March 2019

(b) Examine the following program fragment; What does the fragment write
to the monitor?

int[] array = { 1, 4, 3, 6, 8, 2, 5};


int what = array[0];

// scan the array


for ( int index=0; index < array.length; index++ )
{
if ( array[ index ] < what )
what = array[ index ];
}
System.out.println( what );

(c) Examine the following program fragment; What does the fragment write
to the monitor?

int[] array = { 1, 4, 3, 6 };
int what = 0;

// scan the array


for ( int index=0; index < array.length; index++ )
{
what = what + array[ index ] ;
}
System.out.println( what );
11th
March 2019

4. (a) Write a program, graduate.py, that prompts 20 students for how


many credits they have. Print whether or not they have enough credits
for graduation. Use array to solve this problem.
(At Loyola University Chicago 120 credits are needed for graduation.)

(b) Write a program, graduate.py, that prompts students for how many
credits they have. Print whether or not they have enough credits for
graduation. Use array to solve this problem.
(At Loyola University Chicago 120 credits are needed for graduation.)

5. A courier company, GoFast wants to create a computer program to


determine payable sum to their mileage claims. For customers that has to
pay more than RM300, they will be given a 10% discount. Create a program
for 20 customers and calculate the payable sum together with the number
of customers who receive the 10% discount. The payable sum is based on the
following table. (Use array to solve this problem)
KM RM per KM
First 500 0.50
Next 200 0.40
Each extra KM 0.30

You might also like