日期:2014-05-20 浏览次数:20796 次
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Temp { public static void main(String args[]) throws FileNotFoundException { Scanner in = new Scanner(new File("d:\\test.txt")); System.out.println("杨臣刚 - 老鼠爱大米"); for(int i = 1; i <= 2; i++)//有两行歌词,怎么改写才能终止任意行的循环? { String lyric = in.nextLine(); System.out.println(lyric); } } }
import java.util.Scanner; import java.io.File; import java.io.FileNotFoundException; public class Temp { public static void main(String args[]) throws FileNotFoundException { Scanner in = new Scanner(new File("d:\\test.txt")); System.out.println("杨臣刚 - 老鼠爱大米"); String lyric; while(in.hasNextLine) { lyric = in.nextLine(); System.out.println(lyric); } } }
------解决方案--------------------