STRING TOKENIZER

Input Format:
Input is a string that needs to be split.

Output Format:
Each line of the Output contains two strings. The first string is formed by the token '=' and the second string is formed by the token ';'

Assume The tokens, '=' and ';', will always come alternately. Refer Sample Input.

 

Sample Input:

title=Java-Samples;author=Emiley J;publisher=java-samples.com;copyright=2007;

 

Sample Output:
title Java-Samples
author Emiley J
publisher java-samples.com
copyright 2007

CODE:

import java.io.IOException;
import java.util.Scanner;
import java.util.StringTokenizer;
public class Main {
    public static void main(String[] args) throws IOException {
        Scanner sc = new Scanner(System.in);
    String user = sc.nextLine();
    StringTokenizer st = new StringTokenizer(user,";");
    while(st.hasMoreTokens()) {
    System.out.println((st.nextToken()).replace("=", " "));
    }
}
}

Comments