您的位置:寻梦网首页编程乐园Java天地Core JavaJava Lecture Notes

Introduction

Content

Apply

Reflect

Extend

previous.gif
 (3087 bytes)

next.gif
 (2959 bytes)


Apply Index

Apply Page # 3

Activity 3 – Reversing a 'char' array

(1) Write an applet that displays a char array called forward containing the letters:

'h' 'e' 'l' 'l' 'o'

The screen should look as follows when the appletviewer is executed:

image11.gif (3347 bytes)

(2) Modify your applet so that a second char array, called backward, is created, that processes the elements of array forward, and places the reverse values into array backward.

You should write this code to be general enough so that if the length or values inside forward are changed, your loop to put values into backward does not need to be changed.

image12.gif (3614 bytes)

The screen should look as follows when executed:

(3) Test how general your code is, by changing the characters that forward is initialised to.

For example, try it with the initialisation:

char forward[] =
{ 'I', 'N', 'T', '4', '1', '2', '0', ' ', 'J', 'a', 'v', 'a' };

When executed your screen should appear as follows:

image13.gif (3764 bytes)

Discussion/Suggested solution to Activity 3

Back to content

Back to top

basicline.gif (169 bytes)

RITSEC - Global Campus
Copyright ?1999 RITSEC- Middlesex University. All rights reserved.
webmaster@globalcampus.com.eg