Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using jGrasp and the Software Development Kit, write a program in response to th

ID: 3568873 • Letter: U

Question

Using jGrasp and the Software Development Kit, write a program in response to the following prompt:

Write a program that declares an array "alpha" of 50 elements of type "double". Initialize the array so that the first 25 elements are equal to the square of the index variable and the last 25 elements are equal to three times the index variable. Output the array so that 10 elements per line are printed.

Submit your compiled Java code for this assignment, compress the .java file into a single .zip file.

Explanation / Answer

public class TestClass

{

public static void main(String args[])

{

double[] alpha = new double[50];

/*Now initialize first 25 element the array*/

for(int i = 0; i < 50; i++)

{

if(i<25)alpha[i]= i * i;   // initialize array to square of index if < 25

else alpha[i]= 3 * i; // or else to 3 times the index

}

int i =0;

for(; i <alpha.length;)      //running loop till i< alpha.length

{

System.out.print(alpha[i] +" ");

i++;    //increment i here only so tha we can print a space after every 10th element

if(i%10==0) System.out.println();   //printing a new line after every 10th element .system.out.println() prints just a newline

}

}

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote