A.将1,2,3,4,5输出到屏幕
B. 将0,1,2,3,4输出到屏幕
C. 将0,1,2,3,4,5输出到屏幕
D. 将出现运行时异常
第1题
publicclassTest{
publicstaticintaMethod(inti)throwsException{
try{
returni/10;
}catch(Exceptionex){
thrownewException("exceptioninaaMothod");
}finally{
System.out.print("finally");
}
}
publicstaticvoidmain(String[]args){
try{
aMethod(0);
}catch(Exceptionex){
System.out.print("exceptioninmain");
}
System.out.print("finished");
}
}
A、finallyexceptioninmainfinished
B、exceptioninmainfinally
C、finallyfinished
D、finallyexceptioninmainfinished
第3题
publicclassTest{
publicstaticvoidmain(Stringargs[]){
for(inti=0;i<3;i++){
System.out.print(i)
}
System.out.print(i)
}
}
A.编译时报错
B.正确运行,输出012
C.正确运行,输出123
D.正确运行,输出0123
第4题
程序代码如下:
(1)Java.awt.Graphics;
(2)Java.applet.Applet;
// ////////////////////////////////////////////
// Display y=sin(x)
public class J_DrawSin (2) Applet
{
public void paint(Graphics g)
{
double d, tx;
int x, y, x0, y0;
d=Math.PI/100; // Set step(Set the unit in x direction)
x0=y0=0;
(3)(tx=0, x=20; tx<2*Math.PI; tx+=d,x++)
{
y=120-(int)(Math.sin(tx)*50+60);
if(x>20)
g.drawLine(x0, y0, x, y);
x0=x;
y0=y;
}
g.drawstring("y=sin(x)", 10, 70);
} //End of method: paint
} //End of class: J_HelloApplet
<!-----------------------AppletExample.html------------------->
<HTML>
<HEAD>
<TITLE>
An applet Example ---- Hello Applet!
</TITLE>
</HEAD>
<BODY>
<(4)CODE="J_DrawSin.class" WIDTH=300 HEIGHT=120>
</APPLET>
</BODY>
</HTML>
把所缺代码补充完整。
第7题
java.util.HashMapmap=newjava.util.HashMap();
map.put("name",null);
map.put("name","Jack");
System.out.println(map.get("name"));
A.null
B.Jack
C.nullJack
D.运行时出现异常
第8题
A.0
B.1
C.2
D.3
第9题
【说明】
请完成下列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)
}
}
}
为了保护您的账号安全,请在“上学吧”公众号进行验证,点击“官网服务”-“账号验证”后输入验证码“”完成验证,验证成功后方可继续查看答案!