100分 在线急等,10道JAVA基础试题求解

zhiaini 2008-04-03 10:02:04
1、设计一个矩形类,计算某一给定矩形的面积

2、设有计算阶乘的函数f(n)=n!,试设计一个计算阶乘的方法和相应的类,并利用这个类计算f(5)和f(17)的值

3、简述对象间的通信(消息)与实例方法的调用?

4、定义一个代表学生的类Student,创建该类的3个对象放在一数组中,试将数组的元素依次输出。Student类的属性包括“学号”、“姓名”和“成绩”;方法包括“构造方法”、“获取学号”、“获取姓名”、“获取成绩"

5、编程判断当前目录下是否存在文件file1.txt和file2.txt,如果都存在则将file1.txt的内容写到文件file2.txt中去

6、简述Applet类的主要方法?

7、编写一能接收参数的小应用程序,参数值为字符串“新年快乐”,并写出该小应用程序编译执行的过程

8、编程计算从10到20的平方值,并将结果保存在一个数组中

9、设有计算阶乘的函数f(n)=n!,试设计一个计算阶乘的方法和相应的类,并利用这个类计算f(5)和f(17)的值

10、怎么样理解循环语言,并一实例来说明?


新手求助,很急很急,希望各位一定得帮我,在线等!!!
谢谢谢谢
很急
...全文
1016 62 打赏 收藏 转发到动态 举报
写回复
用AI写文章
62 条回复
切换为时间正序
请发表友善的回复…
发表回复
zhanfen168 2009-06-02
  • 打赏
  • 举报
回复
123
gabriel80 2008-04-30
  • 打赏
  • 举报
回复
[Quote=引用 41 楼 liuqianqian 的回复:]
题目做的都很不错了
不过楼主的题目很面熟啊,估计是在那个时代写过!上学的吧!
[/Quote]
哈哈。怎么跟上学扯上了啊
bootupnow 2008-04-07
  • 打赏
  • 举报
回复
45 -- 53楼是好人,鉴定完毕 ^_^
shili150 2008-04-07
  • 打赏
  • 举报
回复
public int Area(int width,int high){
int width1;
int high1;
width1=width;
high1=high;
int area=width1*high1;
return area;
}//这是获得矩形面积的方法


public int Jiecheng(int i,int k){
int jiecheng=1;
for(int j=1;j<=i;j++){
jiecheng*=j;
}
return jiecheng;
}//这是计算阶乘的方法
zuoguodang 2008-04-07
  • 打赏
  • 举报
回复
不是吧,大哥,如果你想要答案,你也不用这样发帖子要啊,你可以给某一个人的邮箱发email
fzk2015 2008-04-07
  • 打赏
  • 举报
回复
顶!
wren4255 2008-04-07
  • 打赏
  • 举报
回复
顶45-53
huangjinmou 2008-04-06
  • 打赏
  • 举报
回复
我是刚刚接触JAVA,专业课,基础题还是自己多多锻炼的好
montao 2008-04-06
  • 打赏
  • 举报
回复

第九题重复
第十题目 自己上GOOGLE搜索一百 !!!!
sharpyuce 2008-04-06
  • 打赏
  • 举报
回复
问题太难了.........
montao 2008-04-06
  • 打赏
  • 举报
回复
第八题:
package taotao.montao.over;

public class TestNum {

public static void main(String[] args) {
int[] num = work(10, 20);
for (int i = 0; i < num.length; i++) {
System.out.println(num[i]);
}
}

public static int[] work(int start, int end) {
int[] num = new int[end-start+1];
int j = 0;
for (int i = start; i < end+1; i++) {
num[j] = i * i;
j++;
}
return num;
}
}
montao 2008-04-06
  • 打赏
  • 举报
回复

第七题 对不起 我没学过Applte 所以做不出来哦!

对不起
montao 2008-04-06
  • 打赏
  • 举报
回复
第六题目答案:

destroy() 由浏览器或applet viewer调用,通知此applet它正在被回收,它应该销毁分配给它的任何资源。
getAccessibleContext() 获取与此 Applet 有关的 AccessibleContext。
getAppletContext() 确定此applet的上下文,上下文允许 applet 查询和影响它所运行的环境。
getAppletInfo()返回有关此 applet 的信息。
getAudioClip(URL url)返回 URL 参数指定的 AudioClip 对象。
getCodeBase() 获得基 URL。
getDocumentBase() 获取嵌入了此 applet 的文档的 URL。
getImage(URL url) 返回能被绘制到屏幕上的 Image 对象。
getImage(URL url, String name) 返回能被绘制到屏幕上的 Image 对象。
getLocale() 如果已经设置,则获取 applet 的语言环境。
getParameter(String name) 返回 HTML 标记中命名参数的值。
getParameterInfo() 返回此 applet 理解的关于参数的信息。
init() 由浏览器或 applet viewer 调用,通知此 applet 它已经加载到系统中。
isActive() 确定 applet 是否处于激活状态。
newAudioClip(URL url) 从给定 URL 处获取音频剪辑。
play(URL url) 播放在指定的绝对 URL 处的音频剪辑。
resize(Dimension d) 请求调整此 applet 的大小
setStub(AppletStub stub) 设置此 applet 的 stub。
showStatus(String msg) 请求参数字符串显示在 "status window" 中。
start() 由浏览器或 applet viewer 调用,通知此 applet 它应该开始执行。
stop() 由浏览器或 applet viewer 调用,通知此 applet 它应该终止执行。
montao 2008-04-06
  • 打赏
  • 举报
回复
第五题答案:
package taotao.montao.over;

import java.io.*;

public class FileTest {

public static void main(String[] args) {

System.out.println(work());
}

public static String work() {
String msg = null;
File file1 = new File("H:/file1.txt");
File file2 = new File("H:/file2.txt");
BufferedReader br = null;
String fileContent = "";
// 判断是否存在
if (file1.exists() && file2.exists()) {
// 读出file1中的内容
try {
br = new BufferedReader(new FileReader(file1));
String line = "";
while ((line = br.readLine())!= null) {
fileContent += line;
}
msg = "文件COPY已经成功!";
} catch (Exception e) {
e.printStackTrace();
msg = "当前目录下不存在该文件或则读写失败!";
} finally {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}

//写文件
BufferedWriter bw = null;

try {
bw = new BufferedWriter(new FileWriter(file2));
bw.write(fileContent);
} catch (Exception e) {
e.printStackTrace();
}finally
{
try {
bw.flush();
bw.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return msg;
}
}
montao 2008-04-06
  • 打赏
  • 举报
回复
第四题

package taotao.montao.over;

public class StudentTest {

public static void main(String[] args) {

Student student1 = new Student(101,"montao",85.5f);
Student student2 = new Student(102,"yangtao",98.5f);
Student student3 = new Student(103,"taotao",87.7f);

Object[] object = {student1,student2,student3};

//打印
for(int i=0;i< object.length;i++)
{
Student stu = (Student)object[i];
System.out.println("----------学员信息----------");
System.out.println("学员ID:"+stu.getStudentId());
System.out.println("学员姓名:"+stu.getStudentName());
System.out.println("学员分数:"+stu.getMark());
}
}
}

class Student
{
private int studentId;
private String studentName;
private float mark;

public Student(int id,String name,float mark)
{
this.studentId = id;
this.studentName = name;
this.mark = mark;
}

public int getStudentId()
{
return this.studentId;
}

public String getStudentName()
{
return this.studentName;
}

public float getMark()
{
return this.mark;
}
}

montao 2008-04-06
  • 打赏
  • 举报
回复
第三题:
JAVA程序创建对象,对象之间的交互是通过发送消息来实现的。(该理解可以参照3楼的小伙子的答案)
montao 2008-04-06
  • 打赏
  • 举报
回复
第二题:

package taotao.montao.over;

public class TestJieChen {

public static void main(String[] args) {

System.out.println(cunt(5));

}

public static int cunt(int num)
{
int result = 1;
if(num>0)
{
int i = 1;
while(i<=num)
{
result = result*num;
i++;
}
}
return result;
}
}

montao 2008-04-06
  • 打赏
  • 举报
回复
我来做 我这个比较标准 你要给我分哦:

第一题的答案

package taotao.montao.over;

public class Rectangle {

public static void main(String[] args) {
CreateRectangle rectangle = new CreateRectangle(40,50);
int area = rectangle.getArea();
System.out.println("面积是: "+area);
}
}

class CreateRectangle {
int width = 0;
int height = 0;

public CreateRectangle(int width, int height) {
this.width = width;
this.height = height;
}

public int getArea()
{
int area = 0;
area = this.height * this.width;
return area;
}
}
KartChen 2008-04-06
  • 打赏
  • 举报
回复
第5道题目好象是我们青鸟课后练习题
zhqngwu 2008-04-05
  • 打赏
  • 举报
回复
第一题:


/** 平面图形接口 */
public interface PlaneGraphics {

/** 计算面积的方法 */
public double area();

/** 计算周长的方法 */
public double perimeter();

/** 打印方法 */
public void print();
}


/**
* 矩形类myRectangle实现平面图形接口PlaneGraphics
* 其内封装了矩形面积、周长的计算.
*/
public class MyRectangle implements PlaneGraphics {
/** 矩形的长度 */
protected double length;

/** 矩形的宽度 */
protected double width;

/** 两个参数的构造方法 */
public MyRectangle(double length, double width) {
this.length = length;
this.width = width;
}

/** 一个参数的构造方法,此时矩形为正方形 */
public MyRectangle(double width) {
this.length = width;
this.width = width;
}

/** 无参的构造方法 */
public MyRectangle() {
//调用两个参数的构造方法
this(0,0);
}

/** 计算矩形的面积 */
public double area() {
return this.length * this.width;
}

/** 计算矩形的周长 */
public double perimeter() {
return 2*(this.length + this.width);
}

/** 输出矩形的长度、宽度、面积、周长 */
public void print() {
if (this.length == this.width) {
System.out.print("一个正方形,长度为 " + this.length);
} else {
System.out.print("一个长方形,长度为 " + this.length
+ ",宽度为 " + this.width);
}
System.out.println(",面积为 " + this.area()
+ ",周长为 " + this.perimeter());
}

//main()方法用来测试
public static void main(String[] args) {
MyRectangle r1 = new MyRectangle(10, 20);
r1.print();

r1 = new MyRectangle(10);
r1.print();
}
}
加载更多回复(42)

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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