Menu
Topics Index
...
`

United States Of America


If you need explanation Read this topic

If you need Answer Take test on this topic

United States Of America
What will be the output of the following program?
public class UnitedStatesOfAmerica {
    public static void main(String[] args) {
        String s = "UnitedStatesOfAmerica";
        for (int i = 0; i < s.length(); i++) {
            if (i % 3 == 0) continue;
            if (i == 12) break;
            if (i == 9) return;
            System.out.print(s.charAt(i));
        }
    }
}

A. niedta
B. niedtaes
C. UnitedStatesOfAmerica
D. Some other output or Compilation Error
Topic: charAt() Method In Java - Java Character Extraction

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.

Outuput is D because The string UnitedStatesOfAmerica the letters read are niedtaesfAerca.so n i e d t a e s f A e r c a are only satisified with the condition

Posted by Sivani Reddy Kakuru    2014-05-28 09:14:58


Ans is D Since 12 is divisible by 3 the continue statement skips the below statement and the for loop does't break and only the characters of the index which are not divisible by 3 are printed

Posted by Anusha Reddy    2014-05-28 09:22:17


ans is D.
while  I=0,1,2 it satisfies the condition if(i%3==0),and after increment I=3and 3++.. it wil gives another output. --uni.

Posted by RAweeteja Bhonagiri    2014-05-28 10:05:03


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

Posted by Merit Campus    2014-05-29 04:58:27


© meritcampus 2019

All Rights Reserved.

Open In App