题目
请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器目录的内容。
(提示:public String[]list();//将目录中所有文件名保存在字符数组中返回)
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
import java.io.*;
public class FindDirectories
{
public static void main(String args[]
{
if(args.length==0)
args=new String[]{".."};
try
{
_______________
String[] fileName=pathName.list();
for(int i=0;i<fileName.length;i++
{
File f=new File(pathName.getPath() fileName[i]);
if(___________________)
{
System.out.println(f.getCanonicalPath());
main(new String[]
{
f.getPath()
});
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
第1题
请完成下列Java程序。程序的功能是显示用户在命令行方式下指定的任意驱动器文件夹的内容。
提示:public string()list();//将文件夹中所有文件名保存在字符数组中返回。
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
源程序文件代码清单如下:
import java.io.*;
public class FindDirectories
{
public static void main(String args[])
{
if(args.length==0)
args=new String(){".."};
try
{
______;
String[] fileName=pathName.list();
for(int i=0;i<fileName.length;i++)
{
File f=new File(pathName.getPath(),fileName[i]);
if(______)
{
System.out.println(f.getCanonicalPath());
main(new String[]
{
f.getPath()
});
}
}
}
catch(IOException e)
{
e.printStackTrace();
}
}
}
第2题
阅读以下说明和Java代码,将解答写入对应栏内。
【说明】
请完成下列Java程序。程序的执行结果是生成一个具有一个TextField类型的对象in、 Button类型的对象btn和Label类型的对象out图形用户界面,程序的功能是计算用户输入数的平方,如图3所示。
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
【程序】
import java. awt.*;
import java, awt. event.*;
public class square {
public static void main(String args[ ]){
(1)
}
}
class AppFrame. extends Frame{
TheAdapterTest listener = new TheAdapterTest();
Text Field in = new TextField (5);
Button btn = new Button("计算");
Label ut = 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 (2) {
public void actionPerformed((3)) {
String s = in. getText();
double d =(4)
double sq = d * d;
out. setText(d+"的平方是:" +sq);
}
}
class TheAdapterTest extends WindowAdapter
{
public void windowCIosing((5))
{
System. exit(1)
}
}
}
第3题
●试题六
阅读以下说明和Java代码,将解答写入答题纸的对应栏内。
【说明】
请完成下列Java程序。程序的执行结果是生成一个具有一个TextField类型的对象in、Button类型的对象btn和Label类型的对象out图形用户界面,程序的功能是计算用户输入数的平方,如图3所示。
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
【程序】
import javA.awt.*;
import javA.awt.event.*;
public class square {
public static void main(String args[]){
(1)
}
}
class AppFrame. extends Frame{
TheAdapterTest listener=new TheAdapterTest();
TextField in=new TextField (5) ;
Button btn=new Button("计算");
Label ut=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 (2) {
public void actionPerformed((3) ){
String s=in.getText();
double d= (4)
double sq=d*d;
out.setText(d+"的平方是:"+sq);
}
}
class TheAdapterTest extends WindowAdapter
{
public void windowClosing((5) )
{
System.exit (1) ;
}
}
}
第4题
请完成下列Java程序。程序的功能是利用迭代法求一个数的平方根(求平方根的迭代公式为:Xn+1=1/2(Xn+a/Xn)).
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
public class PingFangGen{
public static void main(String args[]){
System. out. println(Math, sqrt(2.0));
}
static double sqrt(______){
double x=1.0
do
{
_______
}
while(Math. abs(x*x-a)/a>le-6)
return x;
}
}
第5题
注意:请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
源程序文件代码清单如下:
import java.awt.*;
import java.awt.event.*;
public class BlueWindow
{
public static void main(String args[])
{
Frame. frm=new Frame. ("欢迎参加Java考试!");
TheAdapterTest listener=new TheAdapterTest();
frm. ______;
frm.setSize(200,200);
frm.setBackground(Color.blue);
frm. ______;
}
}
class TheAdapterTest extends WindowAdapter
{
public void windowClosing(WindowEvent e)
{
System.exit(1);
}
}
第6题
请完成下列Java程序:实现打印出自己的源文件的功能。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
import java.io.*;
import java.util.StringTokenizer;
public class ex27_2{
public static void main(String args[])throws IOException{
FileInputStream fis=new FileInputStream("ex27_2.java");
DataInputStream dis=new DataInputStream(fis);
String str=null;
while(true){
__________________;
if(str==null){
__________________;
}
StringTokenizer st=new StringTokenizer(str);
while(st.hasMoreTokens()){
System.out.print(st.nextToken()+ " " );
}
System.out.println();
}
}
}
第7题
A.JSP沿用Java强大的API功能。
B.JSP允许程序员编写自己的标签库来完成应用程序的特定要求。
C.JSP是与微软的IIS捆绑在一起的,在安装Windows的同时安装IIS,即可运行JSP程序。
D.JSP可以被预编译,提高了程序的运行速度。
第8题
A.JSP沿用Java强大的API功能。
B.JSP允许程序员编写自己的标签库来完成应用程序的特定要求。
C.JSP是与微软的IIS捆绑在一起的,在安装Windows的同时安装IIS,即可运行JSP程序。
D.JSP可以被预编译,提高了程序的运行速度。
第9题
【说明】
下面是一个Applet程序,程序的功能是在显示面板上输出字符串。当html页面被其他窗口遮挡后再次显示时,请给出输出结果。
import java.awt.*;
import java. (1). *;
public class MyApplet (2) Applet {
public void (3) (Graphics g) {
g.drawString(tip,20,40);
tip ="I am Java Applet";
}
public void init() {
tip ="welcome"; }
private (4) tip;
}
<html>
<head>
<title> A Simple Applet </title>
</head>
<body>
<applet code="MyApplet.class" width=800 height=400>
</applet>
</body>
</html>
网页输出 (5)
第10题
阅读以下说明和Java代码,将解答写入对应栏内。
【说明】
下面程序的功能是显示已定义的一个3行3列的二维数组每行的元素,并求所有元素的和并输出。请在程序的每条横线处填写一个适当的语句,使程序的功能完整。
public class Arrayt
(1) static (2) main(String args[])
{
int sum=0;
int [][] = t {11,12,13}, {21,22,23},{31,32,33}};
for(int i=0; (3) i++)
{
System. out. print("b["+i+"]:");
for(int j=0;(4) j++)
System. out. print(b[i] [j] +" ");
(5)
}
System. out. println ();
}
System. out. println("sum="+sum);
}
}
为了保护您的账号安全,请在“赏学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!