Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.io.IOException;
import java.io.StreamTokenizer;
import java.io.StringReader;

public class Main {
    public static void main(String[] args) throws Exception {
        String str = "This is a  test, 200.89  which  is  simple 50";
        StringReader sr = new StringReader(str);
        StreamTokenizer st = new StreamTokenizer(sr);
        try {
            while (st.nextToken() != StreamTokenizer.TT_EOF) {
                switch (st.ttype) {
                case StreamTokenizer.TT_WORD: /* a word has been read */
                    System.out.println("String value: " + st.sval);
                    break;
                case StreamTokenizer.TT_NUMBER: /* a number has been read */
                    System.out.println("Number value:  " + st.nval);
                    break;
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}