Menu
Topics Index
...
`

Rest In Peace ANR


If you need explanation Read this topic

If you need Answer Take test on this topic

Rest In Peace ANR
What will be the output of the following program?
import java.util.*;
public class RestInPeaceANR {
    public static void main(String[] args) {
        List<String> words = new ArrayList<String>();
        words.add("Rest"); words.add("In"); words.add("Peace");
        int index = 0;
        for (String word : words) {
            System.out.print(word + " ");
            words.set(index++, word.toUpperCase());
        }
        Collections.reverse(words);
        for (String word : words) {
            System.out.print(word.charAt(--index));
        }
    }
}

A. Rest In Peace SNP
B. Rest In Peace anR
C. Rest In Peace ANR
D. REST IN PEACE ANR
E. Compilation Error or Runtime Error
Topic: Collection Framework In Java

If you need explanation Read this topic

If you need Answer Take test on this topic

User comments below. All of them might not be correct.

Ans is C..because Rest In Peace  is printed as the contents of ArrayList words and when the contents are reversed using Collections.reverse, ArrayList has [PEACE, IN, REST] and word.charAt(--index) gives A,N,R

Posted by Mamatha Jyothi    2014-01-22 12:56:59


Congratulations Mamatha Jyothi. You are this dose winner. We will send you the link using which you can claim your recharge.

Posted by Merit Campus    2014-01-23 04:11:19


© meritcampus 2019

All Rights Reserved.

Open In App