请完成下列Java程序。程序的输出结果:a=6,b=5。
注意:请勿改动main()主方法和其他已有语句内容,仅在下划线处填入适当的语句。
程序运行结果如下:
public class ex38_2{
public static void main(String args[])
{
int a=5,b=6;
a=_________;
b=a-b;
a=_________;
System.out.println("a="+a+"\tb="+b);
}
}
第1题:
下面程序执行后,输出结果为:true请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class TestStringCompare{
{public static void main(String ____________________ args)
{char charl[]={'t','e','s','t'};
char char2[]={'t','e','s','t','1'};
String str1=new String(___________________);
String str2=new String(char2,0,4);
System.out.println(__________________________);
}
}
第2题:
请完成下列Java程序。实例listener是监听器,frm是事件源,fr上发生的事件委托tat进行处理。程序的执行结果是显示一个蓝色的窗口,单击关闭按钮,可关闭窗口。
注意:请勿改动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);
}
}
第3题:
请完成下列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();
}
}
}
第4题:
下面程序是关于类的继承的用法。阅读下面程序,根据程序中的注释在每一条横线处填写一个语句,使程序的功能完整,且运行程序后的输出结果为:
I am parentclass!
I am childclass!
I am childclass!
注意: 请勿改动main()主方法和其他已有的语句内容,仅在下划线处填入适当的语句。
class Parent {
void printMe() {
System.out.println("I am parentclass!");
}
}
class Child extends Parent {
void printMe() {
System.out.println("I am childclass!");
}
void printAll() {
______________.printMe ( ); // 调用父类的方法
______________. printMe ( ); //调用本类的方法
printMe ( );
}
}
public class TestJieCheng {
public static void main(String args[]) {
______________
myC.printAll();
}
}
第5题:
下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(________)
{
int n=10;
long result=1;
do
{
_______________
}
______________
System.out.println("10的阶乘为: "+result);
}
}