admin 管理员组文章数量: 1086019
2024年3月9日发(作者:if多条件并列判断函数)
Java练习题1(有答案)
第1题 ________ is an object-oriented programming language.
1、 Java
2、 C++
3、 C
4、 Ada
5、 Pascal
答案 1 2
第2题________ is Architecture-
Neutral.
1、 Java
2、 C++
3、 C
4、 Ada
5、 Pascal 答案 1
第3题 ________ is a technical definition of the language that
includes the syntax and semantics of the Java programming
language.
1、 Java language specification
2、 Java API
3、 Java JDK
4、 Java IDE 答案 1
第4题 ________ consists of a set of separate programs for
developing and testing Java programs, each of which is invoked
from a command line.
1、 Java language specification
2、 Java API
3、 Java JDK
4、 Java IDE
答案 3
第5题 ________ provides an integrated development
environment (IDE) for rapidly developing Java programs. Editing,
compiling, building, debugging, and online help are integrated
in one graphical user interface.
1、 Java language specification
2、 Java API
3、 Java JDK
4、 Java IDE 答案 4 第6题
The main method header is written as: 1、
public static void main(string[] args)
2、 public static void Main(String[] args)
3、 public static void main(String[] args)
4、public static main(String[] args)
5、public
void main(String[] args) 答案 3 第7题 Which of
the following statements is correct? 1、Every line
in a program must end with a semicolon.
2、Every statement in a program must end with a semicolon.
3、 Every comment line must end with a semicolon;
4、 Every method must end with a semicolon;
5、Every class must end with a semicolon;
答案 2
第8题 Which of the following statements is correct to display
Welcome to Java on the console?
1、 n( Welcome to Java );
2、 n("Welcome to Java");
3、 n( Welcome to Java );
4、 ( Welcome to Java );
5、 ("Welcome to Java"); 答
案 2 5
第9题Which JDK command is correct to run a Java
application in ?
1、 java ByteCode
2、 java
3、 javac
4、 javac ByteCode
5、 JAVAC ByteCode 答案 1
第10题Suppose you define a Java class as
follows:
public class Test {
}
In order to compile this program, the source code should be
stored in a file named
1、
2、
3、
4、
5、 Any name with extension .java 答案 4 第11题
The extension name of a Java bytecode file is
1、 .java
2、 .obj
3、 .class
4、 .exe 答案 3 第12题 Which of the following lines is
not a Java comment?
1、 /** comments */
2、 // comments
3、 -- comments
4、/* comments */
5、** comments ** 答案3 5 第13题 Which of the
following are the reserved words?
1、 public
2、 static
3、 void
4、 class 答案 1 2 3 4 第14题 To use JOptionPane in
your program, you may import it using:
1、 import nPane;
2、 import .*;
3、 import javax.*;
4、 import javax.*.JOptionPane; 答
案 1 2
第15题 Which of the following are correct names for
variables according to Java naming conventions?
1、 radius
2、 Radius
3、 RADIUS
4、findArea
5、FindArea 答案 1 4 第16题Which of the following are
correct ways to declare variables?
1、 int length; int width;
2、 int length, width;
3、 int length; width;
4、 int length, int width; 答案 1
2 第17题____________ is the Java assignment
operator.
1、 ==
2、 :=
3、 =
4、=: 答案 3 第18题Which of the following assignment
statements is incorrect.
1、 i = j = k = 1;
2、 i = 1; j = 1; k = 1;
3、 i = 1 = j = 1 = k = 1;
4、 i == j == k == 1; 答案 3 4 第19题Which of the following
is a constant, according to Java naming conventions? 1、
MAX_VALUE
2、Test
3、read
4、ReadInt
5、 COUNT 答案 1 5 第20题 To declare an int variable number
with initial value 2, you write
1、 int number = 2L;
2、 int number = 2l;
3、 int number = 2;
4、 int number = 2.0; 答案 3 第
21题 Which of the following expressions will yield 0.5?
1、 1 / 2
2、 1.0 / 2
3、 (double) (1 / 2)
4、 (double) 1 / 2
5、 1 / 2.0 答案 2 4 5 第22题 Which
of the following expression results in a value 1?
1、 2 % 1
2、 15 % 4
3、 25 % 5
4、 37 % 6
答案 4 第23题 -25 % 5
is _____
1、 1
2、 2
3、 3
4、 4
5、 0 答案 5 第24
题 -24 % -5 is _____
1、 3
2、 -3
3、 4
4、-4
5、0 答案 4 第25题To add number to sum, you write (Note:
Java is case-sensitive)
1、 number += sum;
2、 number = sum + number;
3、 sum = Number + sum;
4、 sum += number;
5、sum = sum + number; 答
案4 5
第26题 Suppose x is 1. What is x after x -= 1?
1、 0
2、 1
3、 2
4、 -1
5、 -2 答案 1 第27题 What is x after the following statements?
int x = 1;
int y = 2; x
*= y + 1; 1、
x is 1;
2、 x is 2;
3、 x is 3;
4、 x is 4; 答案
3 第28题What is y
displayed?
public class Test { public static void
main(String[] args) { int x = 1; int y
= x + x++; n("y is "
+ y);
}
}
1、 y is 1.
2、 y is 2.
3、 y is 3.
4、 y is 4. 答案 2 第29题 What is y displayed in the following
code?
public class Test { public static void
main(String[] args) { int x = 1; int y
= x++ + x; n("y is "
+ y);
}
}
1、 y is 1.
2、 y is 2.
3、 y is 3.
4、 y is 4. 答案 3 第30题 What is the printout of the following
code:
double x = 5.5;
int y = (int)x;
n("x is " + x + " and y is " + y);
1、 x is 5 and y is 6
2、 x is 6.0 and y is 6.0
3、 x is 6 and y is 6
4、 x is 5.5 and y is 5
5、 x is 5.5 and y is 5.0 答案 4 第31题 Suppose x is a char
variable with a value b . What is the printout of the statement
n(++x)?
1、 a
2、 b
3、 c
4、 d 答案 3 第32题 Suppose i is an int type variable. Which
of the following statements display the character whose Unicode
is stored in variable i?
1、 n(i);
2、 n((char)i);
3、 n((int)i);
4、 n(i +
" "); 答案 2 第33题 The following code fragment reads
in two numbers: Scanner input = new Scanner();
int i = t(); double d = uble();
What are the correct ways to enter these two numbers?
1、 Enter an integer, a space, a double value, and then the
Enter key.
2、 Enter an integer, two spaces, a double value, and then
the Enter key.
3、 Enter an integer, an Enter key, a double value, and then
the Enter key.
4、 Enter a numeric value with a decimal point, a space, an
integer, and then the Enter key. 答案 1 2 3 第34题 If you enter 1
2 3, when you run this program, what will be the output?
import r;
public class Test1 {
public static void main(String[] args)
{ Scanner input = new Scanner();
("Enter three numbers: ");
double number1 = uble();
double number2 = uble();
double number3 = uble();
// Compute average double average = (number1 +
number2 + number3) / 3; // Display result
n(average);
}
}
1、 1.0
2、 2.0
3、 3.0
4、 4.0 答案 2 第35题 The expression (int)(76.0252175 * 100)
/ 100 evaluates to _________.
1、 76.02
2、 76
3、 76.0252175
4、 76.03 答案 2 第36题 According to Java naming
convention, which of the following names can be variables? 1、
FindArea
2、 findArea
3、 totalLength
4、 TOTAL_LENGTH
5、 class 答案 2 3 第37题 The __________ method displays an
input dialog for reading a string.
1、 String string = ssageDialog(null,
"Enter a string", "Input Demo",
ON_MESSAGE);
2、 String string = putDialog(null, "Enter
a string", "Input Demo", ON_MESSAGE);
3、 String string = putDialog("Enter a
string", "Input Demo", ON_MESSAGE);
4、 String string = putDialog(null, "Enter
a string");
5、String string = putDialog("Enter a
string"); 答案 2 4 5 第38题 Analyze the following code.
import .*; public class
ShowErrors { public static void
main(String[] args) { int i; int j;
String s = putDialog(null,
"Enter an integer", "Input",
ON_MESSAGE);
j = nt(s);
i = (i + 4);
}
}
1、 The program cannot compile because j is not initialized.
2、 The program cannot compile because i does not have an
initial value when it is used in i = i + 4;
3、The program compiles but has a runtime error because i
does not have an initial value when it is used in i = i + 4;
4、The program compiles and runs fine. 答案 2 第39题
Suppose x=10 and y=10. What is x after evaluating the
expression (y > 10) && (x-- > 10)?
1、 9
2、 10
3、 11 答案 2 第40题 Suppose x=10 and y=10 what is x after
evaluating the expression
(y >= 10) || (x++ > 10).
1、 9
2、 10
3、 11 答案 2 第41题 Suppose x = 1, y = -1, and z = 1. What
is the printout of the following statement? (Please indent the
statement correctly first.) if (x > 0) if (y > 0)
n("x > 0 and y > 0");
else if (z > 0)
n("x < 0 and z > 0");
1、 x > 0 and y > 0;
2、 x < 0 and z > 0;
3、 x < 0 and z < 0;
4、 no printout.
答案 2 第42题Analyze the
following code.
boolean even = false;
if (even) {
n("It is even!");
}
1、 The code displays It is even!
2、 The code displays nothing.
3、 The code is wrong. You should replace if (even) with if
(even == true)
4、 The code is wrong. You should replace if (even) with if
(even = true) 答案 2
第43题 The following code displays ___________.
double temperature = 50; if
(temperature >= 100)
n("too hot");
else if (temperature <= 40)
n("too
cold"); else
n("just right");
1、 too hot
2、 too cold
3、 just right
4、 too hot too cold just right 答案
3 第44题Analyze the following
code:
Code 1:
boolean even; if
(number % 2 == 0)
even = true; else
even = false; Code 2:
boolean even = (number % 2 == 0); 1、
Code 1 has compile errors.
2、 Code 2 has compile errors.
3、 Both Code 1 and Code 2 have compile errors.
4、 Both Code 1 and Code 2 are correct, but Code 2 is better.
答案 4 第45题The __________ method immediately terminates the
program.
1、 ate(0);
2、 (0);
3、(0);
4、(0); 答案 3 第46题
What is the printout of the following switch statement?
char ch = a ;
switch (ch)
{ case a :
case A :
(ch); break;
case b : case B :
(ch); break;
case c : case C :
(ch); break;
case d : case D :
(ch);
}
1、 abcd
2、 a
3、 aa
4、 ab
5、 abc 答案 2 第47题 What is the printout of the
following switch statement?
char ch = b ;
switch (ch)
{ case a :
(ch);
case b :
(ch);
case c :
(ch);
case d :
(ch);
}
1、 abcd
2、 bcd
3、 b
4、 bb
5、 bbb 答案 5 第48题 Analyze the following
program fragment: int x; double d = 1.5; switch
(d) { case 1.0: x = 1; case 1.5: x = 2; case 2.0:
x = 3;
}
1、The program has a compile error because the required
break statement is missing in the switch statement.
2、 The program has a compile error because the required
default case is missing in the switch statement.
3、 The switch control variable cannot be double.
4、 No errors. 答案 3
第49题Analyze the following code fragments that assign a
boolean value to the variable even.
Code 1: if (number %
2 == 0) even = true;
else even = false;
Code 2:
even = (number % 2 == 0) ? true:
false; Code 3: even = number % 2 ==
0;
1、 Code 2 has a compile error, because you cannot have
true and false literals in the conditional expression.
2、 Code 3 has a compile error, because you attempt to
assign number to even.
3、 All three are correct, but Code 1 is preferred.
4、All three are correct, but Code 2 is preferred.
5、 All three are correct, but Code 3 is preferred.
答案 5 第50题The statement ("%3.1e",
1234.56) outputs ___________.
1、 0.1e+04
2、 0.123456e+04
3、 0.123e+04
4、 1.2e+03
5、 1.23+03 答案 4
第51题Analyze the following
code: int i = 3434; double d = 3434;
("%5.1f %5.1f", i, d);
1、 The code compiles and runs fine to display 3434.0 3434.0.
2、 The code compiles and runs fine to display 3434 3434.0.
3、 i is an integer, but the format specifier %5.1f specifies a
format for double value. The code has an error.
答案 3 第52题 What is the value of the following
expression?
true || true && false
1、 true
2、false 答案 1 第53题Which of the following
statements are true? 1、 (x > 0 && x < 10) is same
as ((x > 0) && (x < 10))
2、 (x > 0 || x < 10) is same as ((x > 0) || (x < 10))
3、 (x > 0 || x < 10 && y < 0) is same as (x > 0 || (x < 10 &&
y < 0))
4、 (x > 0 || x < 10 && y < 0) is same as ((x > 0 || x < 10) &&
y < 0) 答案 1 2 3 第54题How many times will the following code
print "Welcome to Java"?
int count = 0; while
(count < 10) {
n("Welcome to Java");
count++;
}
1、 8
2、 9
3、 10
4、11
5、0 答案 3 第55题
Analyze the following code.
int count = 0; while
(count < 100) {
// Point A
n("Welcome to Java!");
count++;
// Point B
}
// Point C
1、 count < 100 is always true at Point A
2、 count < 100 is always true at Point B
3、 count < 100 is always false at Point B
4、 count < 100 is always true at Point C
5、 count < 100 is always false at Point C 答案 1 5 第56题
How many times will the following code print "Welcome to Java"?
int count = 0;
do {
n("Welcome to Java");
} while (count++ < 10);
1、 8
2、 9
3、 10
4、 11
5、 0 答案 4 第57题 What is the value in count after the
following loop is executed?
int count = 0;
do {
n("Welcome to Java");
} while (count++ < 9);
n(count);
1、 8
2、 9
3、 10
4、 11
5、 0 答案 3 第58题 Do the following two statements in (I)
and (II) result in the same value in sum?
(I): for (int i = 0; i<10;
++i) { sum += i;
} (II): for (int i = 0; i<10;
i++) { sum += i;
}
1、 Yes
2、 No 答案 1 第59题 Is
the following loop correct? for (; ; );
1、Yes
2、No 答案 1 第60题
Analyze the following code: public
class Test { public static void main
(String args[]) { int i = 0;
for (i = 0; i < 10; i++);
n(i + 4);
}
}
1、 The program has a compile error because of the
semicolon (;) on the for loop line.
2、 The program compiles despite the semicolon (;) on the
for loop line, and displays 4.
3、 The program compiles despite the semicolon (;) on the
for loop line, and displays 14.
4、 The for loop in this program is same as for (i = 0; i < 10;
i++) { }; n(i + 4); 答案 3 4
第61题 To add 0.01 + 0.02 + ... + 1.00, what order should
you use to add the numbers to get better accuracy?
1、 add 0.01, 0.02, ..., 1.00 in this order to a sum variable
whose initial value is 0.
2、add 1.00, 0.99, 0.98, ..., 0.02, 0.01 in this order to a sum
variable whose initial value is 0.
答案 1 第62题 What is sum after the following loop
terminates?
int sum = 0; int
item = 0; do
{ item++; sum +=
item; if (sum > 4)
break;
} while (item <
5);
1、 5
2、 6
3、7
4、8 答案 2 第63题After the continue outer statement is
executed in the following loop, which statement is executed?
outer:
for (int i = 1; i < 10; i++)
{ inner:
for (int j = 1; j < 10; j++)
{ if (i * j > 50) continue
outer; n(i
* j);
} }
next:
1、The control is in the outer loop, and the next iteration of
the outer loop is executed.
2、The control is in the inner loop, and the next iteration of
the inner loop is executed.
3、 The statement labeled next.
4、The program terminates. 答案 1 第64题Suppose the input
for number is 9. What is the output from running the following
program? import r; public class Test {
public static void main(String[] args)
{ Scanner input = new
Scanner();
("Enter an integer: ");
int number = t();
int i;
boolean isPrime = true; for (i = 2; i <
number && isPrime; i++) { if (number %
i == 0) { isPrime = false;
}
}
n("i is " + i);
if (isPrime)
n(number + " is prime");
else
n(number + " is not prime");
}
}
1、 i is 3 followed by 9 is prime
2、 i is 3 followed by 9 is not prime
3、i is 4 followed by 9 is prime
4、i is 4 followed by 9 is not prime 答案 4 第65题 Suppose
your method does not return any value, which of the following
keywords can be used as a return type?
1、 void
2、 int
3、 double
4、 public
5、 None of the above 答案 1 第66题 All Java applications
must have a method __________.
1、 public static Main(String[] args)
2、 public static Main(String args[])
3、 public static void main(String[] args)
4、public void main(String[] args)
5、public static main(String[] args) 答案 3 第67题Does the
return statement in the following method cause compile errors?
public static void main(String[] args)
{ int max = 0; if (max != 0)
n(max);
else
return; }
1、 Yes
2、 No 答案 2 第68题 Does the method call in the following
method cause compile errors?
public static void main(String[] args) {
(2, 4);
}
1、Yes
2、No
答案 2 第69题
Suppose
static void nPrint(String message, int n)
{ while (n > 0) {
(message);
n--; }
}
What is the printout of the call nPrint( a , 4)?
1、 aaaaa
2、 aaaa
3、 aaa
4、 invalid call 答
案 4 第70题
Suppose
static void nPrint(String message, int n)
{ while (n > 0) {
(message);
n--; }
}
What is k after invoking nPrint("A message", k)?
int k = 2; nPrint("A
message", k);
1、 0
2、 1
3、 2
4、 3 答案 3 第71题 Analyze the following code: public class
Test { public static void main(String[] args) {
版权声明:本文标题:Java练习题1(有答案) 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.roclinux.cn/b/1709927766a550026.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论