Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class DivideAndRule {
    public static void main(String[] args) {
        String team = "Pawn Elephant Pawn Knight Pawn Bishop Pawn King Pawn Minister Pawn Bishop Pawn Knight Pawn Elephant";
        StringTokenizer enemy = new StringTokenizer(team);
        while (enemy.hasMoreTokens()) {
            String initial = enemy.nextToken().substring(0, ((String) enemy.nextElement()).length() / 2);
            System.out.print(initial + " ");
        }
    }
}


Pawn Elephant Pawn Knight Pawn Bishop Pawn King
Pawn Elephant Pawn Knight Pawn Bishop Pawn King Pawn Minister Pawn Bishop Pawn Knight Pawn Elephant
Pa Elep Pa Kni Pa Bis Pa Ki Pa Mini Pa Bis Pa Kni Pa Elep
Pawn Paw Paw Pa Pawn Paw Paw Pawn
Some other output
Compilation Error or Runtime Error

Doubts

Problems

Topic: StringTokenizer In Java

Read this topic
Take test on this topic

0
Wrong
Score more than 2 points

© meritcampus 2019

All Rights Reserved.

Open In App