下列程序打包到example包,main方法调用线程类输出0~9这10个数,请填写横线处的内容。
注意:请勿改动main()主方法和其他已有语句内容,仅在横线处填入适当语句。
______
interface MyInterface
{
public abstract void print(int n);
}
class Mythread extends Thread ______ MyInterface
{
public void run()
{
for(int i = 0; i < 10; i++)
this.print(i);
}
public void print(int n)
{
System.out.print(n +" ");
}
}
public class Example1_6
{
public static void main(String argv[])
{
Mythread th = new Mythread();
______
}
}
第1题:
创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承Thread类,二是向Thread类传递一个Runnable对象。请在下面程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class TestThread{
public static void main(String args[ ])
{
MyThread t=new MyThread();
_______________________
}
}
class MyThread_____________Thread{
_____________________
{
for(int i=0;i<10;i++){
System.out.println(" " +i);
}
}
}
第2题:
下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
____________________
public class TestKeyBoardInPut
{public static void main(String[] args)
{String yourname=JOptionPane. ____________________ ("What is your name?");
System.out.println("Hello"+yourname);
____________________.exit(0);
}
}
第3题:
下面的程序是打印输出100~300之间的不能被3整除的数。请在每条横线处填写一条语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填人适当的语句。
public class printNo3and5{
void print()
{
int n ;
for(n=100 ;n<=300 ;n++){
if(n%3==0)
__________
System.out.println(n);
}
}
public static__________main(String args[])
{
printNo3and5 bj=new printN03and5();
__________
}
}
第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);
}
}