Monday 22 August 2011

STRING SPLITING IN JAVA

,
THIS PROGRAM SEPARATE NAME AND NO
CODE:
package javaapplication2;
import java.io.*;

public class Main {

    public static void main(String[] args) throws IOException {

        BufferedReader str = new BufferedReader(new InputStreamReader(System.in));
        String user = new String();
        String temp = new String();
        System.out.println("Enter String:");


        user = str.readLine();

        String[] result = user.split("#");
      String[] name = null;
        String[] number = null;
        int totNum = Integer.parseInt(result[0]);
      //  System.out.println(totNum);
        name = new String[totNum+1];
        number = new String[totNum+1];

        for (int i = 1; i <= totNum; i++) {
           
            name[i]=result[i].split("~")[0];
            number[i]=result[i].split("~")[1];

        }
        System.out.println("Name List:");
for (int i = 1; i <= totNum; i++) {
          
           System.out.println(name[i]);
          
    }
        System.out.println("Number List:");
     for (int i = 1; i <= totNum; i++){
        
    System.out.println(number[i]);
        }
}
}

0 comments to “STRING SPLITING IN JAVA”

Post a Comment