Java | JSP | JSF Answers

Questions: 4 418

Answers by our Experts: 3 943

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Search & Filtering

Write a Java method called append that takes as parameters two arrays a and b and returns an array that contains all the elements of array a followed by all the elements of array b. For example, appending the two arrays: a = {1, 4, 9, 16, 9} and b = {11, 11, 7, 9, 16, 4, 1} returns an array of length 12 containing {1, 4, 9, 16, 9, 11, 11, 7, 9, 16, 4, 1}. Write a Java Tester to test the correctness of the above written method.
20. What is the output of the following code sequence?
// c2 is a C object reference
c2.foo1( );
27. What does this method do?
public static int foo( String [ ][ ] a )
{
int b = 0;
for ( int i = 0; i < a.length; i++ )
{
b++; }
return b; }
11-10. What can you tell about the following method?
public void myMethod( )
{
}
62-9. You coded the following in file Test.java:
int [ ] [ ] a = { { 9, 8, 7, 6 },
{ 10, 20, 30, 40 } };
for ( int j = 0; j <= a[1].length; j++ )
{
if ( a[1][j] == 20 ) // line 14
{
System.out.println( "Found 20 at column index " + j
+ " of second row" );
}
}
The code compiles properly, but when you run, you get the following output:
Found 20 at column index 1 of second row
Exception in thread "main" java.lang.ArraylndexOutOfBoundsException:
at Test.main(Test.java:14)
Explain what the problem is and how to fix it.
53-9. Where is the error in this code sequence?
int [ ][ ] a = { { 1, 2 },
{ 10.1, 10.2 } };
27. What does this method do?
public static int foo( String [ ][ ] a )
{
int b = 0;
for ( int i = 0; i < a.length; i++ )
{
b++; }
return b; }
24. What is the output of this code sequence?
for (int i = 0; i < cities.length; i++ )
{
for ( int j = 0; j < cities[i].length; j++ )
{
if ( cities[i][j] .charAt( 0 ) == 'S' )
System.out.println( cities[i][j] );
} }
11-9. As we add objects to an ArrayList, how can we be sure it has enough capacity?
9-9. An ArrayList can be returned by a method.
true
false
LATEST TUTORIALS
APPROVED BY CLIENTS