这里是我的Java代码:如何留下了一个空值在一个循环中的Java
public class DVD {
public static void main(String[] args) {
DVD newdvd1 = new DVD();
newdvd1.setPlayit("The song is playing \n");
newdvd1.setArtist("Eva Cassidy");
newdvd1.setTitle("Songbird");
newdvd1.setGenre("Blues");
System.out.println(newdvd1.getPlayit());
System.out.println(newdvd1);
DVD newdvd2 = new DVD();
newdvd2.setPlayit("The next song is playing \n");
newdvd2.setArtist("an unknown artist");
newdvd2.setTitle("new song");
System.out.println(newdvd2.getPlayit());
System.out.println(newdvd2);
}
private String artist;
private String title;
private String genre;
private String playit;
public String getPlayit() {
return playit;
}
public void setPlayit(String playit) {
this.playit = playit;
}
public String getArtist() {
return artist;
}
public void setArtist(String artist) {
this.artist = artist;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getGenre() {
return genre;
}
public void setGenre(String genre) {
this.genre = genre;
}
public String toString() {
return ("The artist is called " + artist +
" who is a "+ genre + " singer" +
" and this song is called " + title + ".\n");
}
}
它所输出的是:
The song is playing
The artist is called Eva Cassidy who is a Blues singer and this song is called Songbird.
The next song is playing
The artist is called an unknown artist who is a null singer and this song is called new song.
什么我问的是,在第二首歌曲,因为我不想显示第二首歌曲类型,我该如何离开'空歌手'?
'如果(东西== NULL){doSomethingSpecial(); }' – Thilo 2014-09-25 11:48:41