Pages

2011年3月22日 星期二

[Java] 我寫的Java輸出輸入函式整合Class (將持續更新並修改)

由於JAVA的input跟output跟我之前學的C很不一樣,再加上我學習速度緩慢,到現在JAVA的輸入都還不熟,因此寫下一個Package,直接將所有input、output相關功能整理成為我習慣的使用方式,並包成一個class。

之後只要在程式上方import UncleIo.*,就可以有許多好用的輸出入方式。

目前所有的IO只有以下所列的兩三個,之後會陸續增加,我還在初學Java,有錯誤請多多指導:

//This file was written by Uncle
//This is a code to collect all usefull IO implement of JAVA.
//This code was created by Uncle on 2011/03/22
//Last Updated on 2011/03/22

package UncleIo;
import java.io.*;
import UncleIo.UncleIo;
public class UncleIo
{
public static void main(String s[]) throws IOException
{
//test area

UncleIo uncle = new UncleIo();
uncle.UnclePrintf("Please enter a string:");
String haha = uncle.UncleReadString();
uncle.UnclePrintf("\n%s\n",haha);
uncle.UnclePrintf("Please enter an Integer:");
int h = uncle.UncleGetInt();
uncle.UnclePrintf("%d\n",h);
uncle.UnclePrintf("ByeBye\n");
//UnclePrintf("Please enter a string:");

}
UncleIo()
{

}
void UnclePrintf(String format, Object...thing)
{
System.out.printf(format,thing);
}
int UncleGetInt() throws IOException
{
InputStreamReader inputSR = new InputStreamReader(System.in);
BufferedReader bufR = new BufferedReader(inputSR);
return Integer.parseInt(bufR.readLine());
}

String UncleReadString() throws IOException
{
BufferedReader tmp = new BufferedReader(new InputStreamReader(System.in));
String str = tmp.readLine();
return str;
}
}

沒有留言:

張貼留言