“角谷猜想”指出将一个自然数按以下的规则进行运算:若数为偶数,则除以2;若为奇数乘3加1。将得到的数按该规则重复运算,最终可得1。请在下面程序得每条横线处填写一和语句,使程序的功能完整。(如:输入34,则输出结果为34 17 52 26 13 40 20 10 5 16 8 4 2 1)
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填人适当的语句。
import java.io.*;
class JiaoGu{
public static void main(String args[])
{
System.out.print("\n请输入一个数");
try
{
BufferedReader br=new BufferedReader(new lnputStreamReader(System.in));
String s=" ";
try {
s=br.readline();
}
catch (IOExceptine){
}
__________
while(a! =1)
{
System.out.print(" "+a);
if(a%2==1)
__________
else
a=a/2;
}
System.out.println(" "+a);
}
__________{}
}
}
第1题:
接口是抽象方法和常量的集合,是一种特殊的抽象类。下面的程序是对接口的操作,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________MyInterface
{
public static int NUM=100;
public abstract void print();
}
public class ClassName___________MyInterface
{
public void print()
{
System.out.println(NUM);
}
public static void main(String args[])
{
__________________________
obj .print();
}
}
第2题:
下面的程序是用do-while语句计算10的阶乘。请在程序的每条横线处填写1个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容;仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(______)
{
int n=10;
long result=1;
do
{
_____;
}
_____;
System.out.println("10的阶乘为:"+result);
}
}
第3题:
下面的程序的功能是将数组array下标为奇数的元素相乘(数组的位置是从0开始的),并将乘积存放到变量total中。请在程序的每条横线处填入适当的语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class JiShuJi
{
public static void main(String args[ ])
{
int array[ ]={1,2,3,5,7,9};
long total= ________________________;
for(int i=1;i<=__________________ i++)
{
____________________
i++;
}
System.out.println(total);
}
}
第4题:
创建线程对象,要传递代码与数据,而传递代码与数据有两种方法,一是通过继承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);
}
}
}
第5题:
下面的程序的功能是简单的进行键盘输入测试,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
____________________
public class TestKeyBoardInPut
{public static void main(String[] args)
{String yourname=JOptionPane. ____________________ ("What is your name?");
System.out.println("Hello"+yourname);
____________________.exit(0);
}
}
第6题:
下面是一个Applet小程序,其功能为:以坐标(10,20)为起点,画一条长为80个像素点的绿色直线,请在横线处填写一条语句,使程序的完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
import java.awt.*;
public class test_drawline extends Applet
{
public void paint(_______________)
{
g.setColor(Color.green);
_____________________
}
}
第7题:
下面的程序是用do_while语句计算10的阶乘。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class DoWhileLoop
{
public static void main(________)
{
int n=10;
long result=1;
do
{
_______________
}
______________
System.out.println("10的阶乘为: "+result);
}
}
第8题:
请在每条横线处填写一个语句,使程序的功能完整,且输出结果为91 1。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件代码清单如下:
public class Outer
{
public static void main (String args[]
{
Outer i = new Outer();
i,taskInner();
}
public class Inner
{
private int size;
public void doSomething(int size)
{
_____________//访问局部变量
this. size++; //访问内部类的成员变量
_____________//访问外部类的成员变量
System.out.println(size+" "+this.size+" "+Outer.this.size);
}
}
public void taskInner()
{
___________
k.doSomething(8);
}
private static int size;
}
第9题:
请完成下列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);
}
}
第10题:
下面的程序是求9999以内的“完全数”。所谓完全数是指这样的自然数:它的各个约数(不包括该数自身)之和等于该数自身。如28=1+2+4+7+14就是一个完全数。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class QuanShu{
public static void main(String args[]){
for(int n=l;n<9999;n++)
if(______________)System.out.println(n);
}
public static iht divsum(int n){//该方法功能是求一个数的所有约数
int s=0;
for(int i=l;i<n;i++)
if(_________________)
__________________
return s;
}
}
第11题:
下面的程序的功能是求1~100的奇数的和及该和的平均值。请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class SumAndAve{
public static void main(String args[]){
int count = 0, sum = 0, ave= 0;
for (int i = 1; i<= 100; ______)
if(______)
continue;
else
{
______
sum=sum+i;
}
ave= sum/count;
System.out.println( "sum="+sum);
System.out.println( "ave="+ave);
}
}
第12题:
下面的程序是求字符串的长度及每一个位置上的字符。请在每条横线处填写一条语句,使程序的功能完整。
注意;请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class CharAtOp{
public static void main(String args[ ]){
String str="abcdef";
int size=
System.out.println("字符串str的长度为: "+size);
for(int m=0;___________________m++)
{
_______________________
System.out.println("str中的第"+m+"个字符是: "+c);
}
}
}
第13题:
下面的程序是10000以内的“相亲数”。所谓相亲数是指这样的一对数:甲数的约数之和等于乙数,而乙数的约数等于甲数,(例如220和284是一对相亲数)请在程序的每条横线处填写一条语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class QinShu{
public static void main(String args[ ]){
for(int n=1;n<9999;n++){
int s=divsum(n);
if( )
System.out.println(n+","+s);
}
}
public static int divsum(int n){//该方法的功能是求一个数的所有约数
int s=0;
for(int i=1;____________________i++)
if(____________________)s+=i;
return s;
}
}
第14题:
下面程序执行后,输出结果为: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(__________________________);
}
}
第15题:
下面程序的功能是将数组array下标为奇数的元素相乘(数组的位置是从0开始的),并将乘积存放到变量 total中。请在程序的每条横线处填写—个位运算符,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序代码文件清单如下:
public class JiShuJi
{
public static void main(String args[])
{
int array[ ]={1,2,3,5,7,9};
long total=
for(int i=1;i<=______;i++)
{
______;
i++;
}
System.out.println(total);
}
}
第16题:
下面的程序是求菲波那契(Fibonacci)数列的前10项。已知该数列的前两项都为1,即F(1)=1,F(2)=1;而后面各项满足: F(n)=F(n-1)+F(n-2)。请在程序的每条横线处填写一条语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class Fibonacci{
public static void main(String args[]){
System.out.printtn("Fibonacci is"+" "+"_______________________);
}
static long fib(int n){
if(______________)
return 1;
else
return _________________
}
}
第17题:
下面的程序的功能是求1~100的奇数的和及该和的平均值。请在程序的每条横线处填写一个语句,程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class SumAndAve{
public static void main(String args[ ]){
int count=0,sum=0,ave=0;
for(int i=1;i<=100;____________________)
if(_____________________)
continue;
else
{
___________________
sum=sum+i;
}
ave=sum/count;
System.out.println("sum="+sum);
System.out.println("ave="+ave);
}
}
第18题:
“角谷猜想”指出,将一个自然数按以下的一个简单规则进行运算:若数为偶数,则除以2:若为奇数,则乘以3加1。将得到的数按该规则重复运算,最终可得1。请在下面程序的每条横线处填写一个语句,使程序的功能完整。(如:输入34,则输出结果为34 17 52 26 13 40 20 10 5 16 8 4 2 1)
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
源程序文件清单如下:
import java.io.*;
class JiaoGu
{
public static void main(String args[])
{
System.out.print("\n请输入一个数");
try
{
BufferedReader br=
new BufferedReader(new InputStreamReader(System.in));
Stirng s=br.readLine();
______
while(a!=1)
{
System.out.print(" "+a);
if(a%2==1)
______
else
a=a/2;
}
System.out.println(" "+a);
}
______{ }
}
}
第19题:
下面的程序是打印输出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();
__________
}
}
第20题:
下面程序执行结果为:
1×1=1
2×1=2 2×2=4
3×1=3 3×2=6 3×3=9
9×1=9 9×2=18 9×3=27 9×4=36 9×5=45 9×6=54 9×7=63 9×8=72 9×9=81
请在每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class ForLoopStatement{
public static void main(String args[]){
int m,n;
for(m=1;m<10;_____________)
________________;
System.out.print(m+ "*" + n + "=" + m * n + " " );
_____________}
}
第21题:
阅读以下说明和Java代码,将解答写入对应栏内。
【说明】
下面的程序是从命令行输入3个数传递到public static void main(String args[])方法中 (如java IsTriangle 3 4 5),并判断这3个数能否构成三角形的3条边,并显示相应的结果。请在程序的每条横线处填入适当的语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class IsTriangle{
public static void main( String args[ ]){
int a[] =new (1) [args.(2)];
for(int i=0;i<3;(3))
{
a[i]=(4)
}
if((5))
System. out. println(a[0] +","+a[1] +","+a[2]"能构成三角形的3条边");
else
System. out. println(a[0] +","+a[1] +","+a[2]"不能构成三角形的3条边);
}
}
第22题:
下面是打印输出所有和为10000的连续整数(如:1998,1999,2000,2001,2002)的程序,请在每条横线处填写适当语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
public class Sum10000{
public static void main(String args[ ]){
int i;
int j;
int k;
int sum;
for(i=1;i<=10000;______________){
sum=0;
j=i;
__________________;
while(sum<10000)
{
______________
if(sum==10000) {
for(k=i;k<=j;k++)
System.out.println(k+ "");
System.out.println("********");
}
}
}
}
第23题:
下面是关于字符界面基本输入输出的程序,请在程序的每条横线处填写一个语句,使程序的功能完整。
注意:请勿改动main()主方法和其他已有的语句内容,仅在横线处填入适当的语句。
______________________
public class SimpleCharInOut{
public static void main(String args[]){
char c=" ";
System.out.println("Enter a character please: ");
try{
____________________//接受用户键盘输入的字符并保存在变量c中
}
catch(________________________e){}
System.out.println("You've entered character "+c);
}
}