Question

What would be the result after the following code is executed? final int SIZE = 25;...

What would be the result after the following code is executed?

final int SIZE = 25;

int[] array1 = new int[SIZE];

// Code that will put values in array1

int value = 1;

for (int a = 0; a < array1.length; a++)

{

array1[a] = value;

value = value + array1[a];

}

Homework Answers

Answer #1
// TestCode.java
import java.util.Arrays;
public class TestCode {
    public static void main(String[] args) {
        final int SIZE = 25;
        int[] array1 = new int[SIZE];
        // Code that will put values in array1
        int value = 1;
        for (int a = 0; a < array1.length; a++)
        {
            array1[a] = value;
            value = value + array1[a];
        }

        System.out.println(Arrays.toString(array1));
        System.out.println(value);
    }
}

array1 is [1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072, 262144, 524288, 1048576, 2097152, 4194304, 8388608, 16777216]

value is 33554432

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
3. What will be the value of w after the following section of code executes: int...
3. What will be the value of w after the following section of code executes: int w = 4, q = 3; if (q > 5)       if (w == 7)           w == 3;       else            if (w > 3)               w = 1;            else               w = 0; A.0            B.1              C.2          D.3 4. What will be the value of b after the following section of code executes: int a = 4, b = 0; if (a...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a...
C program. Given the following code: int add_and_double(int a, int b) { int result = (a + b) * 2; return result; } int main() {   int val; val = add_and_double(12, 40); return 0; } where the function main() (i.e. the caller) calls the function add_and_double() (i.e. the callee). Which of the following actions are taken when main() calls the function add_and_double()?  Select all that apply. a. Once the callee returns, the caller frees the stack memory for the callee's function...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________...
1. The conditon of a "while" loop and a "for" loop are executed at the ____________ of these loops. 2. What will the following code fragment print?    for (i = 0; i < 4; i++)        cout << i + 1; cout << i; 3. What is the result in answer below? int int1=16; int int2=5; int answer=0; answer = int1 / int2 + (5 * 2);
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num ==...
Q1: Given the following code, what is returned by tq(4)? int tq(int num){ if (num == 0) return 0; else if (num > 100) return -1; else     return num + tq( num – 1 ); } Group of answer choices: 0 4 -1 10 Q2: Given that values is of type LLNode<Integer> and references a linked list (non-empty) of Integer objects, what does the following code do if invoked as mystery(values)? int mystery(LLNode<Integer> list) {    if (list.getLink() ==...
Code a valid copy constructor for the GrabBag class below: class GrabBag { private: int* values;...
Code a valid copy constructor for the GrabBag class below: class GrabBag { private: int* values; int size; public: GrabBag(); }; #include "GrabBag.h" GrabBag::GrabBag() { size = rand() % 100 + 1;   values = new int[size]; //random array size   for (int i = 0; i < size; i++)   values[i] = rand()% 10 + 1 ;// random array contents   }   
(C++ program) Use the code segment below to answer the two questions that follow. … int...
(C++ program) Use the code segment below to answer the two questions that follow. … int size = 0; cout << “Enter size: “; cin >> size; int sizeCode = size / 10; if (sizeCode == 0)    cout << “extra small”; else if(sizeCode == 1 )    cout << “small”; else if (sizeCode == 2)    cout << “medium”; else if (sizeCode == 3)    cout << “large”; else    cout << “extra large”; //end if … What would...
What would appear in the console window after the code below executes? #include <stdio.h> int main()...
What would appear in the console window after the code below executes? #include <stdio.h> int main() { char myLetter = 'A'; printf("The value of A is %d", myLetter); }
Please find the errors of the following code a) int x[5]; int k = 10; for...
Please find the errors of the following code a) int x[5]; int k = 10; for (k = 0; k <= 5; k++) { x[k] = k -1; } b) int x[5]; for (k = 1; k <= 5; k++) { cout << x[k-1] << endl; } c) int x[5]={1,2,3,4,5}, y[5]; y = x; for (k = 0; k < 5; k++) { cout << y[k] << endl; } d) int size; cin >> size; int myArr[size];
After the following MASM code is executed: MOV EAX, 212 MOV EBX, 19 CDQ DIV EBX...
After the following MASM code is executed: MOV EAX, 212 MOV EBX, 19 CDQ DIV EBX What is the value in the EAX register (in decimal)? What is the value in the EBX register (in decimal)? What is the value in the EDX register (in decimal)?
Answer the following questions: 1. Given the code segments below with n as the problem size,...
Answer the following questions: 1. Given the code segments below with n as the problem size, answer the following questions: //Code Segment 1 (Consider n as a power of 3) int sum = 0; for(int i = 1; i <= n; i = i*3) sum++;​​​​​​​// statement1 //Code Segment 2: (Consider both possibilities for x) if(x < 5){ for(int i = 1; i <= n; i++)    for(int k = 1; k <= i; k++)    sum++;​​​​​// statement2 } else{ for(int...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT