L 3 Necessary Java Programming Techniques Java API

  • Slides: 4
Download presentation
L 3. Necessary Java Programming Techniques Java API (Vector) Continue doing ex 2 Packages

L 3. Necessary Java Programming Techniques Java API (Vector) Continue doing ex 2 Packages Java. util import Java. util. *; Classes Vector Interfaces Enumeration

An example of using class Vector Run Java applet => Vector. Test. html Take

An example of using class Vector Run Java applet => Vector. Test. html Take a look at source code => Vector. Test. java Exercise: 1. Understand run the program. 2. Add a reverse button and it displays the elements in the vector in a reverse order.

Output: Optional exercise: Write a java application program that uses Vector class and can

Output: Optional exercise: Write a java application program that uses Vector class and can output the result as shown in the right. Enter lines of input, use quit to end the program. apple orange banana grape lemon quit Number of lines: 5 Middle line: banana Lines in reverse order: lemon grape banana orange apple Lines in reverse alphabetical order: orange lemon grape banana apple

The program outline: import java. io. *; import java. util. *; public class Reverse.

The program outline: import java. io. *; import java. util. *; public class Reverse. Lines { public static void main (String[] args) throws IOException { Buffered. Reader in = new Buffered. Reader (new Input. Stream. Reader (System. in)); final String STOPPER = "quit"; Vector lines = new Vector(); System. out. println ("Enter lines of input, use " + STOPPER + " to end the program. "); // Read in line of input until user enters stopping value. // Put each line of input into the vector. // your source code // Print the lines in reverse order - step 4 in the handout. // your source code // Print the lines in reverse alphabetical order // your source code } }