I need help with Java bat In Javabat.com under Arrays 1, work on FirstLast6, and
ID: 3829761 • Letter: I
Question
I need help with Java bat
In Javabat.com under Arrays 1, work on FirstLast6, and sum 3. Copy and paste the code and the output of all green PASS signs here. Also, help answer the questions below.
1. What is stored in this array?
int [] sample = new int [8];
int i, k;
for ( k = 0; k < 8; k++)
sample [k] = k - 10;
2. What is stored in this array?
int [] sample = new int [8];
for ( k = 0; k < 8; k++)
if ( k%2 == 0 )
sample [k] = k;
else
sample [ k ] = k + 100;
3. What is stored in this array?
int [] sample = new int [8];
for ( k = 0; k < 8; k++)
if ( k < 3)
sample [ k ] = 1;
else
sample [ k ] = -1;
Explanation / Answer
1. What is stored in this array?
int [] sample = new int [8];
int i, k;
for ( k = 0; k < 8; k++)
sample [k] = k - 10;
Answer: [-10, -9, -8, -7, -6, -5, -4, -3]
2. What is stored in this array?
int [] sample = new int [8];
for ( k = 0; k < 8; k++)
if ( k%2 == 0 )
sample [k] = k;
else
sample [ k ] = k + 100;
Answer: [0, 101, 2, 103, 4, 105, 6, 107]
3. What is stored in this array?
int [] sample = new int [8];
for ( k = 0; k < 8; k++)
if ( k < 3)
sample [ k ] = 1;
else
sample [ k ] = -1;
Answer: [1, 1, 1, -1, -1, -1, -1, -1]
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.