编写JAVA程序,实现记事本基本功能
源代码:
public class Notebook {
private ArrayList<String> notes = new ArrayList<String>();
public void add(String a) {
notes.add(a);
}
public void add(String a,int location) {
notes.add(location,a);
}
public int getsize() {
return notes.size();
}
public String getnote(int index) {
return notes.get(index);
}
public void removenote(int index) {
notes.remove(index);
}
public String[] list() {
String[] b = new String[notes.size()];
notes.toArray(b);
return b;
}
public static void main(String[] args) {
Notebook c = new Notebook();
c.add("今天吃什么?");
c.add("今天天气怎么样?");
c.add("今天你快乐吗?", 1);
System.out.println(c.getsize());
System.out.println(c.getnote(1));
c.removenote(1);
String[] b = c.list();
for(String a:b) {
System.out.println(a);
}
}
}
结果示例: 吾独矣 终极愿望世界和平
|