Menu
Question Index
...

What will be the output of the following program?

import java.util.*;
public class StringTokeninzerImplementer {
    public static void main(String[] args) {
        String mathExpr = "4*2+2/4";
        StringTokenizer st1 = new StringTokenizer(mathExpr, "*+/-", true);
        while (st1.hasMoreTokens()) {
            System.out.print(st1.nextToken() + " ");
        }
        System.out.println();
        String str = "fields1,fields2,fields3,and fields4";
        StringTokenizer st2 = new StringTokenizer(str, ", ", false);
        while (st2.hasMoreTokens()) {
            System.out.print(st2.nextToken() + " ");
        }
    }
}


4 2 2 4
fields1 fields2 fields3 and fields4
4 * 2 + 2 / 4
fields1 fields2 fields3 and fields4
4 2 2 4
4 * 2 + 2 / 4
fields1 , fields2 , fields3 , and   fields4
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