栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > Java面试题

java上机笔试试卷

Java面试题 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

java上机笔试试卷

1基本操作题
下面程序的功能是显示已定义的一个3行3列的二维数组每行的元素,并求所有元素的和并输出。请在程序的每条横线处填写一个适当的语句,使程序的功能完整。
package num1;

public class ShuZu {
public static void main(String[] args) {
int sum = 0;
int b[][] = { { 13, 14, 15 }, { 23, 24, 25 }, { 33, 34, 35 } };

for (int i = 0; ____________ i++) {
System.out.print(“b[” + i + “]: “);
for (int j = 0;____________ j++) {
System.out.print(b[j] + ” “);
_____________
}
System.out.println();
}
System.out.println(“sum=” + sum);
}
}
答案:
1.i < b.length;
2.j < b.length;
3.sum += b[j];

2.简单应用题

请完成下列java程序。程序的执行结果是生成一个具有一个TextFiled类型的对象in、Button类型的对象btn和Label类型的对象out图形用户界面,程序的功能是计算用户输入数的平方。
package num1;
import java.awt.*;
import java.awt.event.*;

public class PingFangShu {
public static void main(String[] args) {
_____________
}
}

class Appframe extends frame {
TheAdapterTest listener = new TheAdapterTest();
TextField in = new TextField(5);
Button btn = new Button(“计算”);
Label out = new Label(“显示计算结果”);

public Appframe() {
setLayout(new FlowLayout());
add(in);
add(btn);
add(out);
btn.addActionListener(new BtnActionAdapter());
addWindowListener(listener);
setSize(400, 100);
show();
}

class BtnActionAdapter implements ActionListener {
public void actionPerformed(ActionEvent e) {
String s = in.getText();
double d = _____________
double sq = d * d;
out.setText(d + “的平方是:” + sq);
}
}

class TheAdapterTest extends WindowAdapter {
public void windowsClosing(WindowEvent e) {
System.exit(1);
}
}
}
答案:
1.new Appframe();
2.Double.parseDouble(s); 或Double.valueOf(s);

3.综合应用题
下面Applet程序的功能是统计在平面坐标系第一象限中,半径大于9,小于10的圆环中坐标值为整数的点有多少?并且给了其坐标值。请改正程序中的错误(有下画线的语句),使程序执行后,能得到预期的结果。
package num1;

import java.applet.*;
import java.awt.*;

public class Di9Ti extends Applet {
public void paint(Graphics g) {
int x, y, r1 = 5, r2 = 4;
int count = 0;
for (x = 1; x < y; x++) {
for (y = 1; y < r1; y) {
if (x * x + y * y < r2 * r2 || x * x + y * y > r1 * r1)
break;
g.drawString(“x=” + x + ” y=” + y, 20 + count * 80, 20);
count++;
}
}

g.drawString(“count=” + count, 20, 40);
}
}
答案:
1. x<r1;
2. y++
3. countinue;

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/264255.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号