急!请大家帮忙做这个递归的java程序!在朋友家里,没有编译器,请帮忙,散分求助大家
1. 给出下面程序的运行结果。
class Father
{
void speak()
{
System.out.println("I am Father");
}
void speak(String s)
{
System.out.println("Father like "+s+".");
}
}
public class Child extends Father
{
void speak()
{
System.out.println("I am Child");
}
void speak(String s)
{
super.speak(s);
}
public static void main(String[] args)
{
Father x=new Father();
x.speak();
Father y=new Child();
y.speak();
y.speak("music");
Child z= new Child();
z.speak("dancing");
}
}
2. 用递归方法编写一个java程序,输出如下数字塔:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5
3.读下面的Java程序,然后写出程序的功能和运行结果
import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.IOException;
class Main1
{
public static void main(String[] args)
{
if(args.length!=1)
{
System.err.println("Usage:java Main1<file>");
System.exit(-1);
}
try
{
FileInputStream in=new FileInputStream(args[0]);
BufferedInputStream bufin=new BufferedInputStream(in,1024);
int count,half=bufin.available()/2;
bufin.skip(half);
byte[] buf=new byte[1024];
while((count=bufin.read(buf,0,buf.length))>0)
for(int i=0;i<count;i++)
System.out.print((char)buf[i]);
System.out.flush();
bufin.close();
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
运行程序时,输入: java Main1 myfile.java 其中myfile.java的内容为:I am apple!