자바 문자입력시 미출력 구문
조회수 427회
import java.util.Scanner;
public class Song {
private String title;
private String artist;
private int year;
private String country;
public void Song(){}
public void Song(int year, String country, String artist, String title) {
this.year = year;
this.country = country;
this.artist = artist;
this.title = title;
}
void show() {
System.out.println(year + "년 " + country + "국적의 " + artist +"가 부른 " + title);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
while(true) {
System.out.println("시작을 원하면 1 끝은 0 입력");
int start = sc.nextInt();
if(start == 0)
break;
else {
System.out.println("년도, 국적, 가수, 제목 순으로 입력");
int year = sc.nextInt();
String country = sc.nextLine();
String artist = sc.nextLine();
String blank = sc.nextLine(); //이부분이 빠져있다면 title이 출력이 안되는데 이유가뭘까요?
String title = sc.nextLine();
Song song = new Song();
song.Song(year, country,artist,title);
song.show();
}
}
}
}
만약 String blank = sc.nextLine(); 구문이 빠져있다면 2021 대한민국 아이유 라일락
이순서로 입력시에 라일락은 출력되자 않고, 2021년 대한민국 국적의 아이유가 부른 // 까지만 출력이 됩니다. 이유가 뭔가요?
-
(•́ ✖ •̀)
알 수 없는 사용자 - 〉
댓글 입력