Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
Lab5
Wooseok Kim
wkim3@albany.edu
www.cs.albany.edu/~wooseok/201
Question Answer Points
1 A 8
2 A 8
3 E 8
4 D 8
5 20
• 5	for class
• 10	for main
• 5	points	 for	
output
6 A 8
7 B 8
8 0 15
9 D 8
10 B 8
Question Answer Points
11 A 8
12 D 8
13 A 8
14 A 8
15 E 8
16 B 8
17 A 8
18 C 8
19 nextInt( 19	)	+	22 20
• 10	for	21
• 10	for	20
20 25
• 10	for	correct	
substring
• 10	for	correct call	
to	length()
• 5	for	correct	
output
Question	1	
The	line	of	Java	code	"//	System.out.println("Hello");"	will	
• A)	do	nothing
• B)	cause	”Hello”	to	be	outupt
• C)	cause a	syntax error
• D)	cause	“(Hello)”	to	be	output
• E)there	is	no	way	to	know	without	executing	this	line	of	code
Question	2
A	unique	aspect	of	Java	that	allows	code	compiled	on	one	machine	to	
be	executed	on	a	machine	of	a	different	hardware	platform	is	Java’s
• A)	bytecodes
• B)	syntax
• C)	use	of	objects
• D)	use	of	exception	handling
• E)	all	of	the	above
Question	2
Question	3
Which	character	below	is	not	allowed	in	an	identifier?
• A)	$
• B)	_
• C)	0	(zero)
• D)	q
• E)	^
Question	4
An	error	in	a	program	that	results	in	the	program	outputting	$100	
instead	of	the	correct	answer,	$250	 is
• A)	A	programmer	error
• B)	A	syntax	error
• C)	A	run-time	error
• D)	A	logical	 error
• E)	A	snafu
Question	4
• B)	A	syntax	error	
• Compile	 Error
• C)	A	run-time	error	
• 12	/	0	=	?
• D)	A	logical	error	
• Incorrect	Answer
Question	5
• Write	a	Java	program	that	will	display	on	two	separate	lines	your	
name	and	your	major.
Question	5	(Grading	Guideline)
• 5	points	for	having	the	keyword	class	and	a	reasonable	class	name	in	
the	right	place
• 2	points	each	for	static,	void,	main(),	String[],	args
• 5	points	for	output	– the	name	and	the	major
Question	6
Following	Java	naming	convention,	which	of	the	following	would	be	the	
best	name	for	a	class	about	store	customers?
• A)	StoreCustomer
• B)	Store	Customer
• C)	storeCustomer
• D)	STORE_CUSTOMER
• E)	Store-Customer
Question	7
If	x	is	an	int and	y	is	a	double,	all	of	the	following	are	legal	except	which	
assignment	statement?
• A)	y	=		(double)	x;
• B)	x	=	y;	
• C)	y	=	x;
• D)	x	=	(int)	y;
• E)	all	of	the	above	are	legal
Question	7
If	x	is	an	int and	y	is	a	float,	all	of	the	following	are	legal	except	which	
assignment	statement?
• A)	y	=		(double)	x;
• B)	x	=	y;	
• int <	double
• C)	y	=	(float)	x;
• D)	x	=	(int)	y;
• E)	all	of	the	above	are	legal
Question	8
• What	will	be	the	result	of	a	in	the	following	assignment	statement?	
Assume	b	=	8	and	c	=	10.
Question	8	(Grading	Guideline)
• 15	pionts
• Up	to	10	points	partical credit	if	they	have	some	correct	work
Question	9
Which	library	package	would	you	import	to	use	NumberFormat and	
DecimalFormat?
• A)	java.beans
• B)	java.io
• C)	java.lang
• D)	java.text
• E)	java.util
Question	10
QuestionNineAndTen computes
• A)	The	correct	average	of	x,	y	and	z	as	a	double
• B)	The	correct	average	of	x,	y	and	z	as	an	int
• C)	The	average	of	x,	y,	and	z	as	a	double,	but	the	result	may	not	be	
accurate
• D)	The	sum	of	x,	y	and	z
• E)	The	remainder	of	the	sum	of	x,	y	and	z	divided	by	3
Question	11
What	is	output	if	x	=	0,	y	=	1	and	z	=	1?
• A)	0
• B)	0.0
• C)	0.66666666
• D)	0.66666667
• E)	0.67
Question	12
In	order	to	create	a	constant,	you	would	use	which	of	the	following	
Java	reserved	words?
• A)	private
• B)	static
• https://www.javatpoint.com/static-keyword-in-java
• C)	int
• D)	final
• E)	class
Question	13
In	Java,	a	variable	may	contain
• A)	a	primitive	 value	or	an	object	reference
• B)	a	package
• C)	a	method
• D)	a	class
• E)	any	of	the	above
Question	14
Mistyping	“println”	as	“printn”	will	result	in
• A)	A	syntax	error	
• B)	A	runtime	error	
• C)	a	logical	error
• D)	no	error	at	all
• E)	Converting	the	statement	into	a	comment
Question	15
What	is	the	function	of	the	dot	operator?
• A)	It	serves	to	separate	the	integer	portion	from	the	fractional	portion	
of	a	floating	point	number
• B)	It	allows	one	to	access	the	data	within	an	object	when	given	a	
reference	to	the	object
• C)	It	allows	one	to	invoke	a	method	within	an	object	when	given	a	
reference	to	the	object
• D)	It	is	used	to	terminate	commands	(much	as	a	period	terminates	a	
sentence	in	English)
• E)	Both	B	and	C	are	correct

Question	16
In	Java,	”instantiation”	means
• A)	noticing	the	first	time	something	is	used
• B)	creating	a	new	object	of	the	class
• C)	creating	a	new	alias	to	an	existing	object
• D)	launching	a	method
• E)	none	of	the	above

Question	17
An	“alias”	when
• A)	Two	different	reference	variables	refer	to	the	same	physical	
object
• B)	Two	different	numeric	variables	refer	to	the	same	physical	object
• C)	Two	different	numeric	variables	contain	identical	values
• D)	Two	variables	have	the	same	names
• E)	none	of	the	above

Question	18.
An	API	is
• A)	an	Abstract	Programming	Interface
• B)	an	Application	Programmer’s	Interface
• C)	an	Application	 Programming	Interface
• D)	an	Abstract	Programmer’s	Interface
• E)	an	Absolute	Programming	Interface
Question	19.
• Complete	the	following	assignment	statement	that	generates	a	
random	number	between	22	(inclusive)	to	40	(inclusive).	
Question	20
• Given	a	String	object	“Computer	Science”	whose	object	reference	is	
major,	use	the	object	reference	to	invoke	proper	String	instance	
methods	to	create	a	substring	containing	“Sci”,	 calculate	the	length	of	
the	substring,	display	both	the	substring	and	its	length	on	the	same	
line.	
String	major	=	new	String(“Computer	Science”);
String	subStringOfMajor;	//Store	the	substring	of	major
int lengthOfMajor;							//Store	the	length	of	the	substring
Question	20
Question	20	(Grading	Guideline)
25	points
• 10	for	correct	substring	call
• take	off	5	points	 if	the	numbers	are	not	correct
• 10	for	correct	call	to	length()
• 5	for	correct	output:	the	substring	and	it’s	length	must	be	on	the	
same	line