/* Method that doubles the value of all elements in a float array * */ public cl
ID: 3573537 • Letter: #
Question
/* Method that doubles the value of all elements in a float array
*
*/
public class DoubleArrayElements
{
public static void main( String [] args )
{
float [] array = { 0.0f, 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f };
System.out.print( "The elements are " );
for ( int i = 0; i < array.length; i++ )
System.out.print( array[i] + " " );
System.out.println( );
System.out.println( "Calling doubleArray method" );
doubleArray( array );
System.out.print( "The elements are " );
for ( int i = 0; i < array.length; i++ )
System.out.print( array[i] + " " );
System.out.println( );
}
// Insert your code here
}
Explanation / Answer
public class DoubleArrayElements{
public static void main(String []args){
float [] array = { 0.0f, 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f };
System.out.print( "The elements are " );
for ( int i = 0; i < array.length; i++ )
System.out.print( array[i] + " " );
System.out.println( );
System.out.println( "Calling doubleArray method" );
doubleArray( array );
System.out.print( "The elements are " );
for ( int i = 0; i < array.length; i++ )
System.out.print( array[i] + " " );
System.out.println( );
}
/* method to double the element of the array */
public static void doubleArray(float[] array ){
for(int i=0;i<array.length;i++)
array[i]=2*array[i];
}
}
/*********OUTPUT**********
The elements are 0.0 1.1 2.2 3.3 4.4 5.5 6.6
Calling doubleArray method
The elements are 0.0 2.2 4.4 6.6 8.8 11.0 13.2
*********OUTPUT**************/
/* Note: I have double the values of array,please ask in case of any doubt,would glad to help you,Thanks */
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.