Question
Please explain how you get the output for each case.
3. What is the output of the following jave code fragments: a. intl A-(1,3,0,2,4) int temp = A[0]; for (int í=0; i< A.length-l; i++) A(幻-A(1+1); AI4]-temp; for (int i: A) System.out.print(ALi] b. intll A-(3,0,2,4,1) int B new int [51: for(int i-o; ǐ< A.length; ǐ++) for (int i: B)System.out.print (B[i] C. int A A-new intl for (int i-0: i A.length-1; 1++) AI4] -temp; for (int i: A)System.out.print (A[ +
0 0
Add a comment Improve this question Transcribed image text
Answer #1

a.
Output: 4 3 2 1 0
Explanation: Left shifted circularly by 1 position

b.
Output: 0 1 2 3 4  
Explanation
i = 0 | A[i] = 3 | A[A[i]] = 4
i = 1 | A[i] = 0 | A[A[i]] = 3
i = 2 | A[i] = 2 | A[A[i]] = 2
i = 3 | A[i] = 4 | A[A[i]] = 1
i = 4 | A[i] = 1 | A[A[i]] = 0

c.
error: array dimension missing
A = new int[];
Given code doesn't compile

Add a comment
Know the answer?
Add Answer to:
Please explain how you get the output for each case. 3. What is the output of...
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
  • In JAVA Thank You What is the exact output produced by running the method test? /**...

    In JAVA Thank You What is the exact output produced by running the method test? /** * TestSwap.java * Demonstrates parameter passing involving arrays and integers, * scope of variables, flow of control, and overloaded methods. */ public class TestSwap { public void swap (int x, int y) { int temp; temp = x; x = y; y = temp; System.out.println("Inside swap version 1:"); System.out.println("x = " + x); System.out.println("y = " + y); } public void swap (int[] a,...

  • What is the output of this code segment? double [] a = {-1.2, 3.1, -4.7, 38.0,...

    What is the output of this code segment? double [] a = {-1.2, 3.1, -4.7, 38.0, 0.0}; double temp = a[0]; for (int i = 1; i < a.length; i++) { if (a[i] < temp) { temp = a[i]; } } System.out.println (temp); What does this method do? In one short English sentence describe the task accomplished by this method. public static int foo(int [] a) { int temp = 0; for (int i = 0; i < a.length; i++)...

  • [10pts] 7) What is the output of the following program? In other words, what is printed...

    [10pts] 7) What is the output of the following program? In other words, what is printed to the screen when you run it? #include <iostream> #include <queue> using namespace std int main) char qu[5] ('a, 'b',c'd','e' queue <char> q int N = 4; char ch for(int í - 0:ì < 5;++1) q.push(qu (]) for (int ǐ 0;i < N;++i) { = ch q.front); q push(ch): q.pop while(!q.emptyO) f cout << q.front ) <<endl; q.pop )

  • QUESTION Z What is the output of the following code: int list[] = {1, 2, 3,...

    QUESTION Z What is the output of the following code: int list[] = {1, 2, 3, 4, 5, 6}; for (int i = 1; i < 6; i++) list[i] = list[i - 1]; for (int i = 0; i < 6; i++) cout << list[i] << ""; 0 1 2 3 4 5 6 0 2345 61 0 111111 0 234 566

  • 1. What is the output of each of the following code segments if the inputs are...

    1. What is the output of each of the following code segments if the inputs are as follows: 5 0 15 -5 2 Scanner input = new Scanner(System.in); int sum = 0; for(int i = 0; i < 5; i++){ System.out.print( “Enter a number”); int number = input.nextInt(); if(number <= 0) break; sum += number; } System.out.println(sum); Second Segment: Scanner input = new Scanner(System.in); int sum = 0; for(int i = 0; i < 5; i++){ System.out.print( “Enter a number”);...

  • Java. what is the output? 17 seconds. Question Completion Status: What is the output of the...

    Java. what is the output? 17 seconds. Question Completion Status: What is the output of the following code: public class ArrayTest public static void main(String[] args) { intl numbers - 13,6,9,12, 15); doSomething (numbers, 4); for (int k0; k<numbers.length; k++) System.out.print (numbers [k) + " "); } public static void doSomething (int[n, int i) { for (int j=0; j<n.length; j++) n[j] = 1; ) ОА. 7 10 13 16 19 B. 6 9 12 15 18 Oc 54321 0.36 9...

  • Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30;...

    Consider the following Java method: public static ArrayList<Integer nums ArrayList<Integer values new ArrayList<Integer0; for(int i=10; i<30; i-i+3) if(i%) values.add(i); return values: What is returned after the method call nums()? a. [12] b. [13] c. [14] d. [15] e. [16] O Which of the following represents the final output of the code segment below? int k: int[]A; A new int[3]: fork-0; k<A.length;k++) A[k]-A.length-k; forſk-0; k<A.length-1; k++) A[k+1]-A[k) for(int i-0;i<A.length;i++) System.out.print(A[i]+" "); a. 222 O b. 333 c. 444 d. 555 O...

  • 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...

  • Please try to explain the answers as well. It will be highly appreciated. Output of the...

    Please try to explain the answers as well. It will be highly appreciated. Output of the following expression: 5 * 4 % 2 = ? Output of a loop: Example: What will be the output of the Java code (Assume all variables are properly declared.) num = 10; while (num <= 32)                 num = num + 5; System.out.println(num); What will be the output of the Java code (Assume all variables are properly declared.) public class test {   ...

  • 5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what...

    for java 5. What is the Output? (2 x 5p each -10p) For cach of the following code snippets write down what will be printed on the screen. (a) for(int a-0; a<5; a++) for (int b-0 b

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
ADVERTISEMENT