Menu
Topics Index
...
`

Character format


If you need explanation Read this topic

If you need Answer Take test on this topic

Character format
What will be the output of the following program?
import java.util.*;
public class CharTest {
    public static void main(String[] args) {
        char input[]={'J','a','V','a',' ','M','e','R','i','T','c','A','m','P','u','S'};
        Formatter name = new Formatter();
        for (int i = 0; i < input.length; i++) {
            if (i % 2 == 0) {
                name.format("%C", input[i]);
            } else {
                name.format("%c", input[i]);
            }
        }
        System.out.println(name);
    }
}

A. JaVa MERITCAMPUS
B. JAVA MeRiTcAmPuS
C. Compilation Error
D. Runtime Error
Topic: Formatting Strings And Characters By Using Formatter

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:A  if statement convverts even characters  to capital letters hence hence the o/p is "Java MERITCAMPUS"

Posted by Indrasena Reddy    2014-02-03 13:09:19


ANS -c

Posted by Kick Bhasha    2014-02-03 13:15:27


A. is ans JaVa MERITCAMPUS..bcz before blank space as %C the same is printed in nxt else continues and convertes all to uppercase

Posted by Shabaaz Shaikz    2014-02-03 13:52:08


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

Posted by Merit Campus    2014-02-04 12:44:21


© meritcampus 2019

All Rights Reserved.

Open In App