java作业 写首歌曲output如下There was an old woman who swallowed a fly.I don't know why she swallowed that fly,Perhaps she'll die.There was an old woman who swallowed a spider,That wriggled and iggled and jiggled inside her.She swallowed the spider to catch the fly,I don't know why she swallowed that fly,Perhaps she'll die.There was an old woman who swallowed a bird,How absurd to swallow a bird.She swallowed the bird to catch the spider,She swallowed the spider to catch the fly,I don't know why she swallowed that fly,Perhaps she'll die.There was an old woman who swallowed a cat,Imagine that to swallow a cat.She swallowed the cat to catch the bird,She swallowed the bird to catch the spider,She swallowed the spider to catch the fly,I don't know why she swallowed that fly,Perhaps she'll die.There was an old woman who swallowed a dog,What a hog to swallow a dog.She swallowed the dog to catch the cat,She swallowed the cat to catch the bird,She swallowed the bird to catch the spider,She swallowed the spider to catch the fly,I don't know why she swallowed that fly,Perhaps she'll die.There was an old woman who swallowed a horse,She died of course.
网友回答
【答案】 1,最最简单就是
System.out.println("There was an old woman who swallowed a fly.");
System.out.println("I don't know why she swallowed that fly,");
以此类推
2,
将以上歌词存入a.txt文件,以放到e盘为例子.
import java.io.*;class A{public static void main(String[] args) throws IOException{File f=new File("e:/a.txt");FileInputStream fis=new FileInputStream(f);File f1=new File("e:/out.txt");FileOutputStream fos=new FileOutputStream(f1);byte[] b=new byte[32];int hasRead;while((hasRead=fis.read(b))>0){//输出到一个文件中fos.write(b,0,hasRead);//输出到控制台System.out.print(new String(b,0,hasRead));}fis.close();fos.close();}}