急!请大家帮忙做这个递归的java程序!在朋友家里,没有编译器,请帮忙,散分求助大家

besthyq 2004-11-13 08:11:35
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!
...全文
168 15 打赏 收藏 转发到动态 举报
写回复
用AI写文章
15 条回复
切换为时间正序
请发表友善的回复…
发表回复
besthyq 2004-11-13
  • 打赏
  • 举报
回复
第三题,程序的功能是什么呢?

就差一点了,,拜托大家了
besthyq 2004-11-13
  • 打赏
  • 举报
回复
第三题,程序的功能是什么呢?

就差一点了,,拜托大家了
besthyq 2004-11-13
  • 打赏
  • 举报
回复
马上结贴,能告诉我第三题程序的功能吗?

题目要求第三题的功能啊
classjava 2004-11-13
  • 打赏
  • 举报
回复
第一个
I am Father
I am Child
Father like music.
Father like dacing
2. 用递归方法编写一个java程序,输出如下数字塔:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

public class Test
{
public static void main(String[] args)
{
print(5);
}
public static void print(int n)
{
if(n>1)
print(n-1);
for(int i=1;i<=n;i++)
{
System.out.print(i);
}
System.out.println("");



}
3. 结果
apple!
好了,结帐算分
besthyq 2004-11-13
  • 打赏
  • 举报
回复
谢谢,,,能告诉我第三题,程序的功能吗?
zhuyupu2004 2004-11-13
  • 打赏
  • 举报
回复
在JBuilder2005中
1. 结果
I am Father
I am Child
Father like music.
Father like dancing.



3. 结果
apple!
okitgo 2004-11-13
  • 打赏
  • 举报
回复
我已经给出所有的答案了,你看一下
besthyq 2004-11-13
  • 打赏
  • 举报
回复
第一个到底是:I am Father
I am Child
Father like music.
Father like dacing
还是:I am Child
Father like music.
Father like dancing.

?????我很菜,,,请教!
okitgo 2004-11-13
  • 打赏
  • 举报
回复
1. 结果
I am Father
I am Child
Father like music.
Father like dancing.

2.程序
class test1
{
public static void main(String[] args)
{
int maxa=5;
for(int i=1;i<=maxa;i++){
for(int j=1;j<=i;j++){
System.out.print(j+" ");
}
System.out.print("\n");
}

}
}

3. 结果
apple!
zhuyupu2004 2004-11-13
  • 打赏
  • 举报
回复
漏了 I am Father. 对不起
I am Father
I am Child
Father like music.
Father like dancing.
zhuyupu2004 2004-11-13
  • 打赏
  • 举报
回复
1. JBuilder2005
I am Child
Father like music.
Father like dancing.
classjava 2004-11-13
  • 打赏
  • 举报
回复
第一个
I am Father
I am Child
Father like music.
Father like dacing
besthyq 2004-11-13
  • 打赏
  • 举报
回复
真的很急啊。。。请帮忙下
besthyq 2004-11-13
  • 打赏
  • 举报
回复
请教大家了,,我散200分求助大家。。。
besthyq 2004-11-13
  • 打赏
  • 举报
回复
请教大家了!

67,513

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧