1. This method takes an array of ints as a parameter and returns an array of boo
ID: 3636982 • Letter: 1
Question
1. This method takes an array of ints as a parameter and returns an array of booleans. For each element in the parameter array whose value is 0, the corresponding element of the array returned will be assigned false, otherwise assigned true.public boolean [ ] foo( int [ ] a )
{
// PLACE CODE HERE
}
2. Where is the error in this code sequence?
Interger i1 = new Interger( 10 );
Integer i2 = new Integer( 15 );
Double d1 - new Double( 3.4 );
String s = new String( "Hello" );
Interer [ ] a = { i1, i2, d1, s };
3. You coded the following in the class Test.java:
int [ ] a = { 1, 2, 2 };
System.out.println( a );
The code compiles properly and runs, but the results is not what you expected; the output is similar to the following: [@f0326267
Explain what the problem is and how to fix it.
Explanation / Answer
please rate - thanks
1. This method takes an array of ints as a parameter and returns an array of booleans. For each element in the parameter array whose value is 0, the corresponding element of the array returned will be assigned false, otherwise assigned true.
public boolean [ ] foo( int [ ] a )
{boolean b[]=new boolean[a.length];
for(int i=0;i<a.length;i++)
if(a[i]==0)
b[i]=false;
else
b[i]=true;
return b;
}
2. Where is the error in this code sequence?
Interger i1 = new Interger( 10 );
Integer i2 = new Integer( 15 );
Double d1 = new Double( 3.4 );
String s = new String( "Hello" );
Interer [ ] a = { i1, i2, d1, s }; a is an integer so d1 and s which are not integers can not be here
3. You coded the following in the class Test.java:
int [ ] a = { 1, 2, 2 };
System.out.println( a );
The code compiles properly and runs, but the results is not what you expected; the output is similar to the following: [@f0326267
Explain what the problem is and how to fix it.
//you aren't printing the values in a your printing what possibly the address of a
fix
int [ ] a = { 1, 2, 2 };
for(int i=0;i<a.length;i++)
System.out.println( a[i] );
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.