linktest.java
来自「Java经典例程 从外国一大学计算机教授出版物下载的代码 经典」· Java 代码 · 共 52 行
JAVA
52 行
import javagently.*;
import java.io.*;
class LinkTest {
/* The LinkTest program J M Bishop Aug 2000
*
* Small test program to
* Illustrate linking of objects through references
*/
LinkTest () throws IOException {
Coffee coffees = null;
String name;
Stream in = new Stream ("names.dat", Stream.READ);
// create a list headed by coffees
System.out.println("Coffees on the list");
for (int i=0; i<=4; i++) {
name = in.readString();
System.out.println(name);
coffees = new Coffee (name, coffees);
}
System.out.println("\nCoffees on the list");
// Copy the head of the list
Coffee list = coffees;
// Print out the list
for (int i=0; i<=4; i++) {
System.out.println(list.name);
list = list.link;
}
}
public static void main (String args []) throws IOException {
new LinkTest();
}
class Coffee {
/* Small test class with a link */
Coffee (String s, Coffee c) {
name = s;
link = c;
}
String name;
Coffee link;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?