Menu
Topics Index
...
`

Seasons


If you need explanation Read this topic

If you need Answer Take test on this topic

Seasons
What will be the output of the following program?
public class Seasons {

    public static void main(String[] args) {
        String s = "summerautumnwinterspring";
        for (int i = 0; i < s.length(); i++) {
            for (int j = 0; j < 6; j++, i++) {
                System.out.print(j == 0 ? Character.toUpperCase(s.charAt(i)) : s.charAt(i));
            }
            System.out.print(" ");
        }
    }
}

A. Summer Autumn Winter Spring 
B. SUMMER AUTUMN WINTER SPRING 
C. Some other output
D. Compilation Error or Runtime Error
Topic: Java Character Class

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 bcz
only the first letter is converted to upper case each time i.e when j=0 and prints it
after every 6 letters v hav a space so v get finally ans a

Posted by Pooja Singh    2014-05-30 12:44:33


ans d. runtim err.
prints Summer Utumn Ntersp aft tat string indxoutof exceptin occur

Posted by Maheshwari Natarajan    2014-05-30 12:59:38


ans is A.
it prints uppercase only at j==0.

Posted by RAweeteja Bhonagiri    2014-05-30 13:12:15


No winner for this dose. Correct option is 'D' :(. Maheshwari Natarajan was already won in this week.

Posted by Merit Campus    2014-06-02 06:59:12


© meritcampus 2019

All Rights Reserved.

Open In App