	   //============================================
       // Numerical Analysis Package in Java
	   // Class Text to read data from screen or file
       // and write (by using print) to screen or file
       // formatted c printf like comand structure
	   // Dr. Turhan Coban
	   //============================================
	   import java.io.*;
	   import java.util.*;

            class Text
            {
            BufferedReader in;
	    /*
            ---------------------------------------------------
            Static routines provided are:
            ---------------------------------------------------
            public static void prompt(String s);
	        public static int readInt(BufferedReader in);
            public static double readDouble(BufferedReader  in);
            public static String readString(BufferedReader in);        
            public static char readChar(BufferedReader in);
	    ----------------------------------------------------
            Dynamic routines provided are :
            ----------------------------------------------------
            public void Text()
            public void Text(String s1)
            public void Text(File f1)
            public int readInt();
            public double readDouble();
            public String readString();        
            public char readChar();

            Sample use :
	    --------- reading a double--------------
            BufferedReader cin=new BufferedReader(new InputStreamReader(System.in));
            double number;
            number=Text.readDouble(cin);
            veya
            double number;
            Text cin=new Text();
            number=cin.readDouble();
	    ------ reading data from a file "datafile.dat"------
            double number;
            BufferedReader fin=new BufferedReader(new FileReader("datafile.dat"));
            double number;
            number=Text.readDouble(fin);
            veya
            double number;
            Text cin=new Text("dataFile.dat");
            number=cin.readDouble();
	    ------ printing data into a file "printfile.dat"----
	    PrintStream fout=new PrintStream
	    (new FileOutputStream("printfile.dat"));
	    String a="turhan";
	    fout.println(a);
        veya
            BufferedWriter fout=new BufferedWriter(new FileWriter("datafile.dat"));
            String a="Turhan");
            fout.write(a);
	    ----------------------------------------------------
	    */
	    private static StringTokenizer T;
	    private static String S;

            public Text() 
            {
            in=new BufferedReader(new InputStreamReader(System.in));
            }

            public Text(String s1)  throws IOException
            {
            in=new BufferedReader(new FileReader(s1));
            }

            public static void prompt (String s) {

	      System.out.print(s + " ");
	      System.out.flush();
	    }

           

            public int readInt() throws IOException
            {
            return Text.readInt(in);
            }

            public double readDouble() throws IOException
            {
            return Text.readDouble(in);
            }

            public String readString() throws IOException
            {
            return Text.readString(in);
            }

            public char readChar() throws IOException
            {
            return Text.readChar(in);
            }

        public static int readInt (BufferedReader in) throws IOException
	    {
	      if (T==null) refresh(in);
	      while (true)
	      {
		try {
		String item = T.nextToken();
		return Integer.valueOf(item.trim()).intValue();
		     }
		catch (NoSuchElementException e1) { refresh (in);
	      } catch(NumberFormatException e2)
                { //System.err.println("Error in number, try again.");
                }
	      }
	     }
             
        public static char readChar (BufferedReader in) throws IOException
	    {
		if (T==null) refresh(in);
		while (true)
		{
		    try {
		     return T.nextToken().charAt(0);
			}
		     catch(NoSuchElementException e1) {refresh (in);}
			}
	    }

        public static double readDouble(BufferedReader in) throws IOException
	    {
		if(T==null) refresh(in);
		while (true) {
		      try {
		       String item = T.nextToken();
		      return Double.valueOf (item.trim()).doubleValue();
			  } catch(NoSuchElementException e1) {
			    refresh (in);
			  } catch(NumberFormatException e2)
                          {
                           //System.err.println("Error in number, try again.");
			  }
		}
	    }

       public static String readString(BufferedReader in) throws IOException
	    {
		if(T==null) refresh (in);
		while (true) {
		    try {return T.nextToken();}
		      catch (NoSuchElementException e1) {
		       refresh (in);
		      }
		}
	    }
            
   public static String readStringLine(BufferedReader in) throws IOException
   {
       //reads a line of strings from BufferedReader in
      int ch;
      String r = "";
      boolean done = false;
      while (!done)
      {  try
	 {  ch = in.read();
	    if (ch < 0 || (char)ch == '\n' || (char)ch == '\0')
	       done = true;
	    else
	       r = r + (char) ch;
	 }
	 catch(java.io.IOException e)
	 {  done = true;
	 }
      }
      return r.substring(0,(r.length()-1));
   }

private static void refresh (BufferedReader in) throws IOException
{
   String s = in.readLine();
   if (s==null) throw new EOFException();
   T = new StringTokenizer(s);
}

}

































