我正在运行我创建的存储用户输入的数据的 java 程序。特别是 4 个数组列表,分别是 songName、songArtist、songYear 和 songAlbum。我有一个“songYear”的用户输入,我只希望程序最多接受 4 位长度并给出错误,否则如何实现?
这是我的添加条目方法的代码:
public void addEntry(){
String newName = ui.getString("Enter the name of the track");
songName.add(newName);
String newArtist = ui.getString("Who performs this track");
songArtist.add(newArtist);
String newAlbum = ui.getString("What album is this track from");
songAlbum.add(newAlbum);
System.out.print("What year was the track released? ");
int newYear=input.nextInt(4);
songYear.add(newYear);
System.out.println("\n" + "Thank you, " +songName.get(songName.size()-1) + " has been added to the library.");
System.out.println("\n" + "Press 2 to view your library." + "\n");
}