Question

Write the output produced by the following program segment. int [] i1Array = new int [5];...

Write the output produced by the following program segment.

int [] i1Array = new int [5];

int [] i2Array;

for (int i = 0; i < i1Array.length; i++){

i1Array[i] = i1Array.length – i; }

i2Array = i1Array;

for (int i = i2Array.length - 1; i >= 0; i--){

i2Array[i] = i1Array[i] * i; }

for (int i = 0; i < i1Array.length; i++){

System.out.println(i1Array[i]); }

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Output of the given code 0 4 6 6 4

Output

0
4
6
6
4
Add a comment
Answer #2

Output of the given code 0 4 6 6 4

answered by: Hasson Ali
Add a comment
Know the answer?
Add Answer to:
Write the output produced by the following program segment. int [] i1Array = new int [5];...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 1. What is the output of the following code segment? int array[] = { 8, 6,...

    1. What is the output of the following code segment? int array[] = { 8, 6, 9, 7, 6, 4, 4, 5, 8, 10 }; System.out.println( "Index Value" ); for ( int i = 0; i < array.length; i++ ) System.out.printf( "%d %d\n", i, array[ i ] ); 2. What is the output of the following code segment? char sentence[] = {'H', 'o', 'w', ' ', 'a', 'r', 'e', ' ', 'y', 'o', 'u' }; String output = "The sentence...

  • What is the output of the following program segment? int count = 5; while(--count > 0)...

    What is the output of the following program segment? int count = 5; while(--count > 0) cout << count << " "; cout << endl;

  • Given the following program segment: int limit = 4; int first = 5 int j; for...

    Given the following program segment: int limit = 4; int first = 5 int j; for (j=1; j <= limit; j++) { cout << first * j << endl; first = first + (j -1); } cout << endl; write a while loop and a do...while loop that both have the same output.

  • 18 C++ 1. What is the output of the following program segment? int y-22: while ((y...

    18 C++ 1. What is the output of the following program segment? int y-22: while ((y 3) != 0) cout << y<< "": y=y-2; The output is 2. Suppose that the input is 100, 20,-8, 50, 20. What is the output of the following C++ code? int sum0 int num: int j cin >> num: if (num < 0) continue зит зит + num; cout<< sum << endl; The output is

  • What is the value of GPA when grade is 'B' in the following code segment? int...

    What is the value of GPA when grade is 'B' in the following code segment? int GPA=0; switch (grade) { case 'A': case 'a': GPA = GPA + 1; case 'B': case 'b': GPA = GPA + 1; case 'C': case 'c': GPA = GPA + 1; case 'D': case 'd': GPA = GPA + 1; } 4 3 2 1 None of the above #2.   Branching - switch statements... Extra info/hint? It's free What is the value of GPA when...

  • Thie What is the output of the following program segment? int count 1; do System.out.print(count (count-)...

    Thie What is the output of the following program segment? int count 1; do System.out.print(count (count-) + while(count++ <= 5);

  • 20) What is the output of the following segment of C code: int avg(int n, int*...

    20) What is the output of the following segment of C code: int avg(int n, int* a); int main () {             int array[4]={1,0,6,9};             printf("%d", avg(4, array)+ 1);             system("pause");             return 0; } int avg(int n, int* a) { int i, sum=0; for (i=0;i<n;i++) { sum+=a[i]; } return sum/n; } a) 16 b) 5 c) 4 d) 8 21) What is the output of the following segment of C code: int x = 2; int y = 3;...

  • JAVA HELP: Directions Write a program that will create an array of random numbers and output...

    JAVA HELP: Directions Write a program that will create an array of random numbers and output the values. Then output the values in the array backwards. Here is my code, I am having a problem with the second method. import java.util.Scanner; import java.util.Random; public class ArrayBackwards { public static void main(String[] args) { genrate(); print(); } public static void generate() { Scanner scanner = new Scanner(System.in);    System.out.println("Seed:"); int seed = scanner.nextInt();    System.out.println("Length"); int length = scanner.nextInt(); Random random...

  • Write the output produced when the following method is passed each of the following lists and...

    Write the output produced when the following method is passed each of the following lists and give the formal code for the problem: public static void mystery1(ArrayList<Integer> list) { for (int i = list.size() - 1; i > 0; i--) { if (list.get(i) < list.get(i - 1)) { int element = list.get(i); list.remove(i); list.add(0, element); } } System.out.println(list); } a. [2, 6, 1, 8] b. [30, 20, 10, 60, 50, 40]

  • 4. Given the following code, int x = 5, n; do{ n = 0; for (int...

    4. Given the following code, int x = 5, n; do{ n = 0; for (int i = 0; i < x; i++) { n = n + x; System.out.println(n); } while (x > 1); a) What will be the value of x after the code segment is executed? Initial value of x 5 b) What is the output of the code segment? c) Explain how the flow of control moves in the given code segment. When explaining, show how...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT