北京联合大学师范学院java期末考试3填空和程序

合集下载
  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

1.Input a integer and assign the result to int variable value. Assume
Scanner variable input can be used to read a value from the keyboard. Value+input.nextInt();
2.Methods of a class are normally made ______ and instance
variables of a class are normally made private. public
3.A ______ method is used to assign values to private instance
variables of a class. set
4.Create a Scanner that reads values from the standard input.
Scanner input=new Scanner(System.in)
5.Java applications begin execution at method ______ .
main
6.All programs can be written in terms of three types of control
structures : sequence, selection and _________. repetition 7.A (n) ________ is not required if you always refer to a class with
its fully qualified class name. import declaration
8.A java program file must end with the _______ file extension.
java
9.A house is to a blueprint as a(n) ______is to a class. object
10.Every class declaration contains keyword _______ followed
immediately by the class’s name.class
11.Keyword_______ creates an object of the class specified to the
right of the keyword. new
12.By default, classes that are compiled in the same directory are
considered to be in the same packageknown as the _______.
Default package
13.When each object of a class maintains its own copy of an
attribute, the field that represents the attribute is also known as a (n) _______. Instance variable
14.Return type ______ indicates that a method will perform a task
but will not return any information when it completes its task.
void
15.Class String is in package. ng
16.Types in Java are divided into two categories primitive types and
___ types. reference
17.Instance variables of types char , byte , short , int , long , float
and double are all given the value ________ by default.
0(zero)
18.Calculate the value of 2.5 raised to the power of 3, using the pow
method: ________. Double result =Math.pow(2.5,3)
21. In a double-subscripted array, the first subscript identifies the row of an element and the second subscript identifies the ____ of an element. ( column).
22. In the Java coordinate system, y values increase _____. (from top to bottom)
23. The _____ class is used to create a group of JradioButtons and it inherits from class ______. (ButtonGroup,Object)
24. The new operator dynamically allocates memory for an object of
a specified type and returns a _____ to that type.(reference)
25.The keyword ____ specifies that an object or variable is not modifiable after it is initialized. (final)
26. An object of a sub class ______(can/can not) be treated as an object of its corresponding super class. (can)
27. A method declared static cannot access ____ class members. (nonstatic)
33.Members of a class specified as ______ are accessible only to methods of the class. (private)
28. A(or An) ______ is a collection of abstract methods that can be implemented to simulate multiple inheritance.( interface)
29. A “has a” relationship between classes represents _____ and an “is a” relationship between classes rep resents inheritance. (composition,)
30. A subclass may call any nonprivate superclass method by prepending ____ to the method call. (super)
31.The Graphics is a/an ________ class and inherits directly from class Object. (abstract)
32. A Jpanel object ___ (is/is not)capable of receiving mouse events.( is)
33.Method ____ is called when the mouse is moved and an event listener is registered to handle the event.(mouseMoved)
35. Class members are accessed via the ______ operator in conjunction with a reference to an object of the class.( dot(.))
36. A superclass typically represents a _____(larger/smaller) number of objects than its subclass represents. (larger)
37. A subclass typically encapsulates ____ (less/more) functionality than does its superclass. (more)
程序填空
1.
_______ java.until.Scanner;
Public class Addition
{
Public ______ void main(String args[])
{
//create Scanner to obtion input from command window
Scanner input= ________ ;
Int number1;//first number to add
Int number2;//sceond number to add
Int sum;//sum of number 1 and number2
System.out.print(“Enter first integer:”);//prompt
Number1=input.nextint();//read first number from user
System.out.print(“Enter first integer:”);//prompt
Number2= __________ ;//read second number from user
__________ ;//add numbers
System.out.printf(“Sum is %d\n”,sum);//display sum }//end method main
}//end class Addition
1import
2static
3new Scanner(system.in)
4input.nextInt()
5sum=number1+number2
2.下面的方法的功能是生成1~36之间的K个(方法参数指定)随即整数,保存到ArrayList对象中并返回,请将程序补充完整。

public static ______ select(int k){
Random rd = ________;//创建随即类对象,用来生成随即数ArrayList allNum = new ArrayList();
ArrayList kNum = new ArrayList();
For(int i=0;i<36;i++) {
_________;//生成36个随机数并添加到allNum中
}
Int x;
For(i=0;i<36;i++){
X=rd.nextint(36-1);
kNum.add(allNum.get(x));
________;//从allNum中移走选中的数
}
________;//返回结果
}
1ArrayList
2New Random()
3allNum.add(i+1)
4allNum.remove(x)
5return kNum
下面的方法求任意多个双精度数的平均值,并返回结果,请将程序补充完整。

public static double average( _____________ xxx ) {
double total = 0.0;
for ( double d : xxx )
total += d;
return total /_______________;
}
阅读下面的程序,请将程序补充完成。

import java.awt.FlowLayout;
import java.awt.event.*;
import javax.swing.*;
public class ButtonFrame _____________ JFrame {
private JButton plainJButton;
public ButtonFrame() {
super("Testing Buttons");
setLayout(new FlowLayout());
plainJButton = new JButton("Plain Button");
add(plainJButton);
plainJButton.addActionListener(_______________________ _{
public void actionPerformed(ActionEvent event) {
JOptionPane.showMessageDialog(
ButtonFrame.this,
String.format("You pressed: %s",
event.getActionCommand()));
}
});
}
public static void main(String args[]) {
ButtonFrame buttonFrame = new ButtonFrame();
buttonFrame.setDefaultCloseOperation(JFrame.EXIT_ON_C LOSE);
buttonFrame.setSize(275, 110);
buttonFrame.setVisible(true);
}
}
编程题
Write a method isEven that uses the remainder operator (%) to determine whether an integer is even. The method should take an integer argument and turn true if the integer is even and false
otherwise. Incorporate this method into am application that inputs a sequence of integers(one at a time )and determines whether each is even or odd.
Import java.util.Scanner;
Public class EvenOdd
{
Public void checkEvenOdd()
{
Scanner input= new Scanner(System.in) ;
While(input.hasNext())
{
Int number=input.nextInt();
If( isEven(number))
System.out.printf(“%d is even\n”,number);
else
System.outprintf(%d is odd\n”,number);
}
}
Public Boolean isEven(int number
{
Return number%2
}
}
根据题目的描述,完成下面的程序。

(1)编写一个static方法find(int num),方法的返回值为int,方法的功能是求整数num的各位数字的和并返回。

(2)编写应用程序,使用JOptionPane类的方法showInputDialog( ),输入一个数字字符串,将其转化为整数后在命令行输出,并调用(1)的方法,输出该数的各位数字和。

编写下图1所示菜单的形界面应用程序;点击菜单则弹出图2所示的对话框。

图1 图2。

相关文档
最新文档