• Tidak ada hasil yang ditemukan

(1 mark) and 4 more like this

N/A
N/A
Protected

Academic year: 2023

Membagikan "(1 mark) and 4 more like this"

Copied!
5
0
0

Teks penuh

(1)

SECOND SEMESTER, 2007

Campus: City

COMPUTER SCIENCE TEST

Principles of Programming

(Time allowed: 75 MINUTES)

NOTE: AttemptALL questions

Write your answers in the space provided

There is space at the back for answers that overflow the allotted space No calculators are permitted

Surname:

Forenames:

Student ID number:

Login name:

(2)

CompSci 101 Test Results

Question Marks Out of

Question 1 10

Question 2 5

Question 3 5

Question 4 10

Question 5 20

Question 6 10

TOTAL 60

(3)

What is displayed by each of the following pieces of Java program?

a) System.out.println("Hello world");

(1 mark) and 9 more like this.

Question 2 (5 marks)

Add the return type to the following Java methods:

a)

private same(double d) { return d;

}

(1 mark) and 4 more like this.

Question 3 (5 marks)

a) Write a Javaboolean expression which tests if the value of theint variable, apple, is not zero.

(1 mark) and 4 more like this.

Question 4 (10 marks)

(These all have quite-short answers.)

Complete each of the methods below as specified in the comment preceding each method.

a)

// method to find the longer of two Strings private String longer(String s1, String s2){

}

(2 marks)

(4)

Question 5 (20 marks)

(This question has longer answers but all of the methods are very similar to those that you have seen in assignments and lectures.)

a. Complete the methodisAllVowels() which accepts aString parameters and returns the boolean valuetrue if everychar ins is a vowel,false otherwise. You may make use of the methodisVowel() that returnstrue orfalse depending on whether itschar parameter is a vowel.

// method to find whether a String s is all vowels private boolean isAllVowels( String s) {

}

(5 marks) and 3 more like this.

Question 6 (10 marks)

a) What is the output when the following program is executed? (This one involves understanding for- loops and Strings.)

// mystery program public void start() {

String s = "abcde";

for (int i=0; i<s.length(); i++){

System.out.println(s.substring(0,i+1));

} } }

Show the output here:

(5 marks) b) What is the output when the following program is executed? (This one involves for-loops, arrays, and methods with array parameters.)

// mystery program Show the output here:

(5 marks)

(5)

Referensi

Dokumen terkait

Bagaimana mungkin para pelaku usaha UKM di SMESCO Indonesia dapat mencapai kinerja perusahaan sedangkan untuk membiayai biaya operasional saja tidak cukup apalagi

It is always necessary to pay close attention in order to reveal the various secrets hidden behind this uniqueness, because every style of language displayed in the Quran is not