Menu
Topics Index
...
`

Rest In Peace ANR2531


If you need explanation Read this topic

If you need Answer Take test on this topic

Rest In Peace ANR2531
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) {
            words.set(index++, word.toUpperCase());
            System.out.print(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.

answer is {B} as after reversing array list we are printing characters 2 ,1,0 of Peace,In, Rest respectively

Posted by Ashok Kumar Paritala    2014-06-13 08:55:47


ans d
1st for loop prints rest in peace all lettr caps
2nd prints ANR
1st from rest, 2nd frm in,3 letter frm peace ..reversd ANR and printd

Posted by NagaRaj Nataraj    2014-06-13 08:59:07


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

Posted by Merit Campus    2014-06-16 03:38:41


© meritcampus 2019

All Rights Reserved.

Open In App