Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 12-09-2007, 05:53 AM
Member
 
Join Date: Dec 2007
Posts: 1
hiaslpix is on a distinguished road
few java questions
1. Arrays are:
a. variable-length entities.
b. fixed-length entities.
c. data structures that contain up to 10 related data items.
d. used to draw a sequence of lines, or “rays.”

2. Which of the following statements about arrays are true?
A. Arrays are a group of variables containing values that all have the same type.
B. Elements are located by index or subscript.
C. The length of an array c is determined by the expression c.length();.
D. The zeroth element of array c is specified by c[ 0 ].

a. A, C, D.
b. A, B, D.
c. C, D.
d. A, B, C, D.


3. Consider the array:
s[ 0 ] = 7
s[ 1 ] = 0
s[ 2 ] = -12
s[ 3 ] = 9
s[ 4 ] = 10
s[ 5 ] = 3
s[ 6 ] = 6
The value of s[ s[ 6 ] - s[ 5 ] ] is:
a. 0.
b. 3.
c. 9.
d. 0.
Ans: c.

4. A programmer must do the following before using an array:
a. declare then reference the array.
b. create then declare the array.
c. create then reference the array.
d. declare then create the array.


5. Consider the code segment below. Which of the following statements is not true?
int g[];
g = new int[ 23 ];
a. The first statement declares an array reference.
b. The second statement creates the array.
c. g is a reference to an array of integers.
d. The value of g[ 3 ] is -1.

6. Which of the following statements about creating arrays and initializing their elements is not true?
a. The new keyword should be used to create an array.
b. When an array is created, the number of elements must be placed in square brackets following the type of element being stored.
c. The elements of an array of integers have a value of null before they are initialized.
d. A for loop is an excellent way to initialize the elements of an array.


7. What do the following statements do?
double array[];
array = new double[ 14 ];
a. Creates a double array containing 13 elements.
b. Creates a double array containing 14 elements.
c. Creates a double array containing 15 elements.
d. Declares but does not create a double array.

8. Which of the following initializer lists would correctly set the elements of array n?
a. int n[] = { 1, 2, 3, 4, 5 };.
b. array n[ int ] = { 1, 2, 3, 4, 5 };.
c. int n[ 5 ] = { 1; 2; 3; 4; 5 };.
d. int n = new int( 1, 2, 3, 4, 5 );.

9. Constant variables also are called .
a. write-only variables.
b. finals.
c. named constants.
d. All of the above.


10. Which of the following will not produce a compiler error?
a. Changing the value of a constant after it is declared.
b. Changing the value at a given index of an array after it is created.
c. Using a final variable before it is initialized.
d. All of the above will produce compiler errors.

11. Consider the class below:
public class Test
{
public static void main( String args[] )
{
int a[];
a = new int[ 10 ];

for ( int i = 0; i < a.length; i++ )
a[ i ] = i + 1 * 2;

int result = 0;
for ( int i = 0; i < a.length; i++ )
result += a[ i ];

System.out.printf( "Result is: %d\n", result );
} // end main
} // end class Test
The output of this Java program will be:
a. Result is: 62.
b. Result is: 64.
c. Result is: 65.
d. Result is: 67.


12. Consider the class below:
public class Test
{
public static void main( String args[] )
{
int a[] = { 99, 22, 11, 3, 11, 55, 44, 88, 2, -3 };

int result = 0;
for ( int i = 0; i < a.length; i++ )
{
if ( a[ i ] > 30 )
result += a[ i ];
} // end for

System.out.printf( "Result is: %d\n", result );
} // end main
} // end class Test
The output of this Java program will be:
a. Result is: 280.
b. Result is: 154.
c. Result is: 286.
d. Result is: 332.

13. Which flag in a format specifier indicates that values with fewer digits than the field width should begin with a leading 0?
a. p.
b. l.
c. w.
d. 0.

14. Which of these statements can be used to complete the following sentence?
Invalid possibilities for array indices include .
a. Positive integers.
b. Negative integers.
c. Non-consecutive integers.
d. Zero.

15. Which expression adds 1 to the element of array arrayName at index i?
a. ++arrayName[ i ].
b. arrayName++[ i ].
c. arrayName[ i++ ].
d. None of the above.


16. Attempting to access an array element out of the bounds of an array, a(n) occurs.
a. ArrayOutOfBoundsException.
b. ArrayElementOutOfBoundsException.
c. ArrayIndexOutOfBoundsException.
d. ArrayException.
Ans: c.

17. Consider integer array values, which contains 5 elements. Which statements successfully swap the contents of the array at index 3 and index 4?
a.
values[ 3 ] = values[ 4 ];
values[ 4 ] = values[ 3 ];
b.
values[ 4 ] = values[ 3 ];
values[ 3 ] = values[ 4 ];
c.
int temp = values[ 3 ];
values[ 3 ] = values[ 4 ];
values[ 4 ] = temp;
d.
int temp = values[ 3 ];
values[ 3 ] = values[ 4 ];
values[ 4 ] = values[ 3 ];


18. In this question, assume a class, Book, has been defined. Which set of statements creates an array of Book objects?
a.
Book books[];
books = new Book[ numberElements ];
b.
Book books[];
books = new Book()[ numberElements ];
c.
new Book() books[];
books = new Book[ numberElements ];
d. All of the above.

19. Assume array items contains the values 0, 2, 4, 6 and 8. Which of the following set of statements uses the enhanced for loop to display each value in array items?
a.
for ( int i = 0; i < items.length; i++ )
System.out.prinf( "%d\n", items[ i ] );
b.
for ( int i : items )
System.out.prinf( "%d\n", items[ i ] );
c.
for ( int i : items )
System.out.prinf( "%d\n", i );
d.
for ( int i = 0 : items.length )
System.out.prinf( "%d\n", items[ i ] );


19. Which of the following tasks cannot be performed using an enhanced for loop?
a. Multiplying all the values in an array together.
b. Displaying all even elements in an array.
c. Comparing the elements in an array to a specific value.
d. Incrementing the value stored in each element of the array.

19. Which statement correctly passes array items to method takeArray? Array items contains 10 elements.
a. takeArray( items[] ).
b. takeArray( items ).
c. takeArray( items[ 9 ] ).
d. Arrays cannot be passed to methods—each item must be sent to the method separately.


20. Consider array items, which contains the values 0, 2, 4, 6 and 8. If method changeArray is called with the method call changeArray( items, items[ 2 ] ), what values are stored in items after the method has finished executing?
public static void changeArray( int passedArray[], int value )
{
passedArray[ value ] = 12;
value = 5;
} // end method changeArray
a. 0, 2, 5, 6, 12.
b. 0, 2, 12, 6, 8.
c. 0, 2, 4, 6, 5.
d. 0, 2, 4, 6, 12.

21. When an argument is passed by reference:
a. a copy of the argument’s value is passed to the called method.
b. changes to the argument do not affect the original variable’s value in the caller.
c. the called method can access the argument’s value in the caller directly and modify that data.
d. the original value is removed from memory.


22. In Java, multidimensional arrays:
a. are not directly supported.
b. are implemented as arrays of arrays.
c. are often used to represent tables of values.
d. All of the above.


23. In array items, which expression below retrieve the value at row 3 and column 5?
a. items[ 3 ].[ 4 ].
b. items[ 3[ 4 ] ].
c. items[ 3 ][ 4 ].
d. items[ 3, 4 ].


24. An array with m rows and n columns is not:
A. An m-by-n array.
B. An n-by-m array.
C. A two-dimensional array.
D. A dual-transcripted array.

a. A and C.
b. A and D.
c. B and D.
d. B and C.

25. Which statement below initializes array items to contain 3 rows and 2 columns?
a. int items[][] = { { 2, 4 }, { 6, 8 }, { 10, 12 } };.
b. int items[][] = { { 2, 6, 10 }, { 4, 8, 12 } };.
c. int items[][] = { 2, 4 }, { 6, 8 }, { 10, 12 };.
d. int items[][] = { 2, 6, 10 }, { 4, 8, 12 };.


26. For the array in the previous question, what is the value returned by items[ 1 ][ 0 ]?
a. 4.
b. 8.
c. 12.
d. 6.

27. Which of the following statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?
a. int items[][] = { { 1, null, null, null }, { 2, 3, 4, 5 }, { 6, 7, null, null } };.
b. int items[][] = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 } };.
c. int items[][] = { { 1 }, { 2, 3, 4, 5 }, { 6, 7 }, {} );.
d. int items[][] = { { 1 }, { 4 }, { 2 } };.

28. Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?
a.
int items[][];
items = new int[ 3 ][ ? ];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
b.
int items[][];
items = new int[ 3 ][ ];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
c.
int items[][];
items = new int[ ? ][ ? ];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];
d.
int items[][];
items[ 0 ] = new int[ 1 ];
items[ 1 ] = new int[ 4 ];
items[ 2 ] = new int[ 2 ];

29. can be used to traverse a two-dimensional array.
a. A do while statement.
b. A for statement.
c. Two nested for statements.
d. Three nested for statements.

30. Which set of statements totals the items in each row of two-dimensional array items, and displays each total?
a.
int total = 0;

for ( int row = 0; row < items.length; row++ )
{
total = 0;

for ( int column = 0; column < a[ row ].length; column++ )
total += a[ row ][ column ];

System.out.printf( "%d\n", total );
}
b.
int total = 0;

for ( int row = 0; row < items.length; row++ )
{
for ( int column = 0; column < a[ row ].length; column++ )
total += a[ row ][ column ];

System.out.printf( "%d\n", total );
}
c.
int total = 0;

for ( int row = 0; row < items.length; row++ )
{
for ( int column = 0; column < a[ column ].length; column++ )
total += a[ row ][ column ];

System.out.printf( "%d\n", total );
}
d.
int total = 0;

for ( int row = 0; row < items.length; row++ )
{
total = 0;

for ( int column = 0; column < a[ column ].length; column++ )
total += a[ row ][ column ];

System.out.printf( "%d\n", total );
}

31. An argument type followed by a(n) in a method’s parameter list indicates that the method receives a variable number of arguments of that particular type.
a. square brackets ([]).
b. ellipsis ( ).
c. varargs keyword.
d. All of the above are acceptable to indicate a variable number of arguments.

32. Which command below runs TestProgram, and passes in the values files.txt and 3?
a. java TestProgram files.txt 3.
b. java TestProgram files.txt, 3.
c. java TestProgram "files.txt", "3".
d. java TestProgram (the arguments files.txt and 3 were passed in when the application was compiled).


33. Which method call converts the value in variable stringVariable to an integer?
a. Convert.toInt( stringVariable ).
b. Convert.parseInt( stringVariable ).
c. Integer.parseInt( stringVariable ).
d. Integer.toInt( stringVariable ).
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-09-2007, 07:19 AM
Senior Member
 
Join Date: Jul 2007
Posts: 1,189
hardwired is on a distinguished road
1 - a
2 - b
3 - c
4 - d
5 - d
6 - c
7 - b
8 - a
9 - c
10 - c
11 - c
12 - c
13 - d
14 - b
15 - a
16 - c
17 - c
18 - a
19 - c
19 - a
19 - b
20 - d
21 - c
22 - d
23 - items[2][4]
24 - c
25 - a
26 - d
27 - b
28 - b
29 - c
30 - a
31 - b
32 - a
33 - c
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 12-31-2007, 07:29 AM
CaptainMorgan's Avatar
Moderator
 
Join Date: Dec 2007
Location: NewEngland, US
Posts: 841
CaptainMorgan will become famous soon enoughCaptainMorgan will become famous soon enough
Send a message via AIM to CaptainMorgan
hardwired, are you serious? I am curious to your reasoning behind completely and 100% giving the answers to this homework/quiz/exam (unless they're completely bogus answers). What good does this serve? How does this help the original poster?
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 12-31-2007, 06:22 PM
tim's Avatar
tim tim is offline
Senior Member
 
Join Date: Dec 2007
Location: South Africa
Posts: 334
tim is on a distinguished road
I agree with you CaptainMorgan. This does look like some assignment.
__________________
If your ship has not come in yet then build a lighthouse.
Bookmark Post in Technorati
Reply With Quote
  #5 (permalink)  
Old 01-01-2008, 06:47 AM
Eranga's Avatar
Moderator
 
Join Date: Jul 2007
Location: Colombo, Sri Lanka
Posts: 3,581
Eranga has a spectacular aura aboutEranga has a spectacular aura about
Send a message via Yahoo to Eranga
And also it is better if the poster can keep short there message. And also don't get your assignment without any attempt at all. First of all try something to do.
__________________
Use an appropriate Subject. "Help, urgent!" isn't one.
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

Has someone helped you? Then you can
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
their helpful post.

Want to make your IDE the best?
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
2 simple java questions jimJohnson New To Java 2 02-02-2008 10:35 AM
www.javaadvice.com - The one stop resource for all your Java questions and answers JAdmin Reviews / Advertising 0 01-24-2008 08:53 PM
Just a Few Questions pringle New To Java 21 01-09-2008 07:21 PM
A few questions about Java and design ldb88 New To Java 4 12-07-2007 01:51 AM
3 Questions hiranya AWT / Swing 4 11-14-2007 05:57 AM


All times are GMT +3. The time now is 08:17 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org