1.設(shè)計(jì)4個(gè)線程镜沽,其中兩個(gè)線程每次對(duì)j增加1茵乱,另外兩個(gè)線程對(duì)j每次減少1。寫出程序搜变。
以下程序使用內(nèi)部類實(shí)現(xiàn)線程采缚,對(duì)j增減的時(shí)候沒(méi)有考慮順序問(wèn)題。
public class ThreadTest1{
private int j;
public static void main(String args[]){
ThreadTest1 tt=new ThreadTest1();
Inc inc=tt.new Inc();
Dec dec=tt.new Dec();
for(int i=0;i<2;i++){
Thread t=new Thread(inc);
t.start();
t=new Thread(dec);
t.start();
}
}
private synchronized void inc(){
j++;
System.out.println(Thread.currentThread().getName()+"-inc:"+j);
}
private synchronized void dec(){
j--;
System.out.println(Thread.currentThread().getName()+"-dec:"+j);
}
class Inc implements Runnable{
public void run(){
for(int i=0;i<100;i++){
inc();
}
}
}
class Dec implements Runnable{
public void run(){
for(int i=0;i<100;i++){
dec();
}
}
}
}
2.編程題: 用最有效率的方法算出2乘以8等于幾?
2 << 3
3.編程題: 寫一個(gè)Singleton出來(lái)挠他。
Singleton模式主要作用是保證在Java應(yīng)用程序中扳抽,一個(gè)類Class只有一個(gè)實(shí)例存在。
一般Singleton模式通常有幾種種形式:
第一種形式:
定義一個(gè)類殖侵,它的構(gòu)造函數(shù)為private的摔蓝,它有一個(gè)static的private的該類變量,在類初始化時(shí)實(shí)例話愉耙,通過(guò)一個(gè)public的getInstance方法獲取對(duì)它的引用,繼而調(diào)用其中的方法贮尉。
public class Singleton {
private Singleton(){}
//在自己內(nèi)部定義自己一個(gè)實(shí)例,是不是很奇怪朴沿?
//注意這是private 只供內(nèi)部調(diào)用
private static Singleton instance = new Singleton();
//這里提供了一個(gè)供外部訪問(wèn)本class的靜態(tài)方法猜谚,可以直接訪問(wèn)
public static Singleton getInstance() {
return instance;
}
}
第二種形式:
public class Singleton {
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
//這個(gè)方法比上面有所改進(jìn)败砂,不用每次都進(jìn)行生成對(duì)象,只是第一次
//使用時(shí)生成實(shí)例魏铅,提高了效率昌犹!
if (instance==null)
instance=new Singleton();
return instance; }
}
其他形式:
定義一個(gè)類,它的構(gòu)造函數(shù)為private
的览芳,所有方法為static
的斜姥。
一般認(rèn)為第一種形式要更加安全些
4.寫一個(gè)Singleton出來(lái)。
Singleton模式主要作用是保證在Java應(yīng)用程序中沧竟,一個(gè)類Class只有一個(gè)實(shí)例存在铸敏。
一般Singleton模式通常有幾種種形式:
第一種形式:
定義一個(gè)類,它的構(gòu)造函數(shù)為private的悟泵,它有一個(gè)static的private的該類變量杈笔,在類初始化時(shí)實(shí)例話,通過(guò)一個(gè)public的getInstance方法獲取對(duì)它的引用,繼而調(diào)用其中的方法糕非。
public class Singleton {
private Singleton(){}
//在自己內(nèi)部定義自己一個(gè)實(shí)例蒙具,是不是很奇怪?
//注意這是private 只供內(nèi)部調(diào)用
private static Singleton instance = new Singleton();
//這里提供了一個(gè)供外部訪問(wèn)本class的靜態(tài)方法朽肥,可以直接訪問(wèn)
public static Singleton getInstance() {
return instance;
}
}
第二種形式:
public class Singleton {
private static Singleton instance = null;
public static synchronized Singleton getInstance() {
//這個(gè)方法比上面有所改進(jìn)禁筏,不用每次都進(jìn)行生成對(duì)象,只是第一次
//使用時(shí)生成實(shí)例衡招,提高了效率篱昔!
if (instance==null)
instance=new Singleton();
return instance; }
}
其他形式:
定義一個(gè)類,它的構(gòu)造函數(shù)為private的蚁吝,所有方法為static的旱爆。
一般認(rèn)為第一種形式要更加安全些
Hashtable和HashMap
Hashtable繼承自Dictionary類,而HashMap是Java1.2引進(jìn)的Map interface的一個(gè)實(shí)現(xiàn)
HashMap允許將null作為一個(gè)entry的key或者value窘茁,而Hashtable不允許
還有就是怀伦,HashMap把Hashtable的contains方法去掉了,改成containsvalue和containsKey山林。因?yàn)閏ontains方法容易讓人引起誤解房待。
最大的不同是,Hashtable的方法是Synchronize的驼抹,而HashMap不是桑孩,在
多個(gè)線程訪問(wèn)Hashtable時(shí),不需要自己為它的方法實(shí)現(xiàn)同步框冀,而HashMap
就必須為之提供外同步流椒。
5.現(xiàn)在輸入n個(gè)數(shù)字,以逗號(hào)明也,分開(kāi)宣虾;然后可選擇升或者降序排序惯裕;按提交鍵就在另一頁(yè)面顯示按什么排序,結(jié)果為绣硝,提供reset
import java.util.*;
public class bycomma{
public static String[] splitStringByComma(String source){
if(source==null||source.trim().equals(""))
return null;
StringTokenizer commaToker = new StringTokenizer(source,","); String[] result = new String[commaToker.countTokens()];
int i=0;
while(commaToker.hasMoreTokens()){
result[i] = commaToker.nextToken();
i++;
}
return result;
}
public static void main(String args[]){
String[] s = splitStringByComma("5,8,7,4,3,9,1");
int[] ii = new int[s.length];
for(int i = 0;i<s.length;i++){
ii[i] =Integer.parseInt(s[i]);
}
Arrays.sort(ii);
//asc
for(int i=0;i<s.length;i++){
System.out.println(ii[i]);
}
//desc
for(int i=(s.length-1);i>=0;i--){
System.out.println(ii[i]);
} } }
6.內(nèi)部類的實(shí)現(xiàn)方式?
示例代碼如下:
package test;
public class OuterClass
{
private class InterClass
{
public InterClass()
{
System.out.println("InterClass Create");
}
}
public OuterClass()
{
InterClass ic = new InterClass();
System.out.println("OuterClass Create");
}
public static void main(String[] args)
{
OuterClass oc = new OuterClass();
}
}
輸出結(jié)果:
C:>java test/OuterClass
InterClass Create
OuterClass Create
再一個(gè)例題:
public class OuterClass {
private double d1 = 1.0;
//insert code here
}
You need to insert an inner class declaration at line 3. Which two inner class declarations are
valid?(Choose two.)
A. class InnerOne{
public static double methoda() {return d1;}
}
B. public class InnerOne{
static double methoda() {return d1;}
}
C. private class InnerOne{
double methoda() {return d1;}
}
D. static class InnerOne{
protected double methoda() {return d1;}
}
E. abstract class InnerOne{
public abstract double methoda();
}
說(shuō)明如下:
一.靜態(tài)內(nèi)部類可以有靜態(tài)成員蜻势,而非靜態(tài)內(nèi)部類則不能有靜態(tài)成員。 故 A鹉胖、B 錯(cuò)
二.靜態(tài)內(nèi)部類的非靜態(tài)成員可以訪問(wèn)外部類的靜態(tài)變量握玛,而不可訪問(wèn)外部類的非靜態(tài)變量;return d1 出錯(cuò)甫菠。
故 D 錯(cuò)
三.非靜態(tài)內(nèi)部類的非靜態(tài)成員可以訪問(wèn)外部類的非靜態(tài)變量挠铲。 故 C 正確
四.答案為C、E
7.Java 的通信編程淑蔚,編程題(或問(wèn)答)市殷,用JAVA SOCKET編程愕撰,讀服務(wù)器幾個(gè)字符刹衫,再寫入本地顯示?
Server端程序:
package test;
import java.net.*;
import java.io.*;
public class Server
{
private ServerSocket ss;
private Socket socket;
private BufferedReader in;
private PrintWriter out;
public Server()
{
try
{
ss=new ServerSocket(10000);
while(true)
{
socket = ss.accept();
String RemoteIP = socket.getInetAddress().getHostAddress();
String RemotePort = ":"+socket.getLocalPort();
System.out.println("A client come in!IP:"+RemoteIP+RemotePort);
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
String line = in.readLine();
System.out.println("Cleint send is :" + line);
out = new PrintWriter(socket.getOutputStream(),true);
out.println("Your Message Received!");
out.close();
in.close();
socket.close();
}
}catch (IOException e)
{
out.println("wrong");
}
}
public static void main(String[] args)
{
new Server();
}
};
Client端程序:
package test;
import java.io.*;
import java.net.*;
public class Client
{
Socket socket;
BufferedReader in;
PrintWriter out;
public Client()
{
try
{
System.out.println("Try to Connect to 127.0.0.1:10000");
socket = new Socket("127.0.0.1",10000);
System.out.println("The Server Connected!");
System.out.println("Please enter some Character:");
BufferedReader line = new BufferedReader(new
InputStreamReader(System.in));
out = new PrintWriter(socket.getOutputStream(),true);
out.println(line.readLine());
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println(in.readLine());
out.close();
in.close();
socket.close();
}catch(IOException e)
{
out.println("Wrong");
}
}
public static void main(String[] args)
{
new Client();
}
};
8.用JAVA實(shí)現(xiàn)一種排序搞挣,JAVA類實(shí)現(xiàn)序列化的方法(二種)带迟? 如在COLLECTION框架中,實(shí)現(xiàn)比較要實(shí)現(xiàn)什么樣的接口囱桨?
用插入法進(jìn)行排序代碼如下:
package test;
import java.util.*;
class InsertSort
{
ArrayList al;
public InsertSort(int num,int mod)
{
al = new ArrayList(num);
Random rand = new Random();
System.out.println("The ArrayList Sort Before:");
for (int i=0;i<num ;i++ )
{
al.add(new Integer(Math.abs(rand.nextInt()) % mod + 1));
System.out.println("al["+i+"]="+al.get(i));
}
}
public void SortIt()
{
Integer tempInt;
int MaxSize=1;
for(int i=1;i<al.size();i++)
{
tempInt = (Integer)al.remove(i);
if(tempInt.intValue()>=((Integer)al.get(MaxSize-1)).intValue())
{
al.add(MaxSize,tempInt);
MaxSize++;
System.out.println(al.toString());
} else {
for (int j=0;j<MaxSize ;j++ )
{
if
(((Integer)al.get(j)).intValue()>=tempInt.intValue())
{
al.add(j,tempInt);
MaxSize++;
System.out.println(al.toString());
break;
}
}
}
}
System.out.println("The ArrayList Sort After:");
for(int i=0;i<al.size();i++)
{
System.out.println("al["+i+"]="+al.get(i));
}
}
public static void main(String[] args)
{
InsertSort is = new InsertSort(10,100);
is.SortIt();
}
}
9.編程:編寫一個(gè)截取字符串的函數(shù)仓犬,輸入為一個(gè)字符串和字節(jié)數(shù),輸出為按字節(jié)截取的字符串舍肠。 但是要保證漢字不被截半個(gè)搀继,如“我ABC”4,應(yīng)該截為“我AB”翠语,輸入“我ABC漢DEF”叽躯,6,應(yīng)該輸出為“我ABC”而不是“我ABC+漢的半個(gè)”肌括。
代碼如下:
package test;
class SplitString
{
String SplitStr;
int SplitByte;
public SplitString(String str,int bytes)
{
SplitStr=str;
SplitByte=bytes;
System.out.println("The String is:'"+SplitStr+"';SplitBytes="+SplitByte);
}
public void SplitIt()
{
int loopCount;
loopCount=(SplitStr.length()%SplitByte==0)?(SplitStr.length()/SplitByte):(SplitStr.length()/Split
Byte+1);
System.out.println("Will Split into "+loopCount);
for (int i=1;i<=loopCount ;i++ )
{
if (i==loopCount){
System.out.println(SplitStr.substring((i-1)*SplitByte,SplitStr.length()));
} else {
System.out.println(SplitStr.substring((i-1)*SplitByte,(i*SplitByte)));
}
}
}
public static void main(String[] args)
{
SplitString ss = new SplitString("test中dd文dsaf中男大3443n中國(guó)43中國(guó)人
0ewldfls=103",4);
ss.SplitIt();
}
}
10.JAVA多線程編程点骑。 用JAVA寫一個(gè)多線程程序,如寫四個(gè)線程谍夭,二個(gè)加1黑滴,二個(gè)對(duì)一個(gè)變量減一,輸出。
1.可能會(huì)讓你寫一段Jdbc連Oracle的程序,并實(shí)現(xiàn)數(shù)據(jù)查詢.
程序如下:
package hello.ant;
import java.sql.*;
public class jdbc
{
String dbUrl="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String theUser="admin";
String thePw="manager";
Connection c=null;
Statement conn;
ResultSet rs=null;
public jdbc()
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
c = DriverManager.getConnection(dbUrl,theUser,thePw);
conn=c.createStatement();
}catch(Exception e){
e.printStackTrace();
}
}
public boolean executeUpdate(String sql)
{
try
{
conn.executeUpdate(sql);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
return false;
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
rs=conn.executeQuery(sql);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}
public void close()
{
try
{
conn.close();
c.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ResultSet rs;
jdbc conn = new jdbc();
rs=conn.executeQuery("select * from test");
try{
while (rs.next())
{
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
11.ORACLE大數(shù)據(jù)量下的分頁(yè)解決方法。一般用截取ID方法滩褥,還有是三層嵌套方法穷躁。
程序如下:
package hello.ant;
import java.sql.*;
public class jdbc
{
String dbUrl="jdbc:oracle:thin:@127.0.0.1:1521:orcl";
String theUser="admin";
String thePw="manager";
Connection c=null;
Statement conn;
ResultSet rs=null;
public jdbc()
{
try{
Class.forName("oracle.jdbc.driver.OracleDriver").newInstance();
c = DriverManager.getConnection(dbUrl,theUser,thePw);
conn=c.createStatement();
}catch(Exception e){
e.printStackTrace();
}
}
public boolean executeUpdate(String sql)
{
try
{
conn.executeUpdate(sql);
return true;
}
catch (SQLException e)
{
e.printStackTrace();
return false;
}
}
public ResultSet executeQuery(String sql)
{
rs=null;
try
{
rs=conn.executeQuery(sql);
}
catch (SQLException e)
{
e.printStackTrace();
}
return rs;
}
public void close()
{
try
{
conn.close();
c.close();
}
catch (Exception e)
{
e.printStackTrace();
}
}
public static void main(String[] args)
{
ResultSet rs;
jdbc conn = new jdbc();
rs=conn.executeQuery("select * from test");
try{
while (rs.next())
{
System.out.println(rs.getString("id"));
System.out.println(rs.getString("name"));
}
}catch(Exception e)
{
e.printStackTrace();
}
}
}
12.用jdom解析xml文件時(shí)如何解決中文問(wèn)題?如何解析?
看如下代碼,用編碼方式加以解決:
package test;
import java.io.*;
public class DOMTest
{
private String inFile = "c:\\people.xml";
private String outFile = "c:\\people.xml";
public static void main(String args[])
{
new DOMTest();
}
public DOMTest()
{
try
{
javax.xml.parsers.DocumentBuilder builder =
javax.xml.parsers.DocumentBuilderFactory.newInstance().newDocumentBuilder();
org.w3c.dom.Document doc = builder.newDocument();
org.w3c.dom.Element root = doc.createElement("老師");
org.w3c.dom.Element wang = doc.createElement("王");
org.w3c.dom.Element liu = doc.createElement("劉");
wang.appendChild(doc.createTextNode("我是王老師"));
root.appendChild(wang);
doc.appendChild(root);
javax.xml.transform.Transformer transformer =
javax.xml.transform.TransformerFactory.newInstance().newTransformer();
transformer.setOutputProperty(javax.xml.transform.OutputKeys.ENCODING, "gb2312");
transformer.setOutputProperty(javax.xml.transform.OutputKeys.INDENT, "yes");
transformer.transform(new javax.xml.transform.dom.DOMSource(doc),
new
javax.xml.transform.stream.StreamResult(outFile));
}
catch (Exception e)
{
System.out.println (e.getMessage());
}
}
}
13.編程用JAVA解析XML的方式.
用SAX方式解析XML,XML文件如下:
<?xml version="1.0" encoding="gb2312"?>
<person>
<name>王小明</name>
<college>信息學(xué)院</college>
<telephone>6258113</telephone>
<notes>男,1955年生,博士轻纪,95年調(diào)入海南大學(xué)</notes>
</person>
事件回調(diào)類SAXHandler.java
import java.io.*;
import java.util.Hashtable;
import org.xml.sax.*;
public class SAXHandler extends HandlerBase
{
private Hashtable table = new Hashtable();
private String currentElement = null;
private String currentValue = null;
public void setTable(Hashtable table)
{
this.table = table;
}
public Hashtable getTable()
{
return table;
}
public void startElement(String tag, AttributeList attrs)
throws SAXException
{
currentElement = tag;
}
public void characters(char[] ch, int start, int length)
throws SAXException
{
currentValue = new String(ch, start, length);
}
public void endElement(String name) throws SAXException
{
if (currentElement.equals(name))
table.put(currentElement, currentValue);
}
}
JSP內(nèi)容顯示源碼,SaxXml.jsp:
<HTML>
<HEAD>
<TITLE>剖析XML文件people.xml</TITLE>
</HEAD>
<BODY>
<%@ page errorPage="ErrPage.jsp"
contentType="text/html;charset=GB2312" %>
<%@ page import="java.io.*" %>
<%@ page import="java.util.Hashtable" %>
<%@ page import="org.w3c.dom.*" %>
<%@ page import="org.xml.sax.*" %>
<%@ page import="javax.xml.parsers.SAXParserFactory" %>
<%@ page import="javax.xml.parsers.SAXParser" %>
<%@ page import="SAXHandler" %>
<%
File file = new File("c:\\people.xml");
FileReader reader = new FileReader(file);
Parser parser;
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
SAXHandler handler = new SAXHandler();
sp.parse(new InputSource(reader), handler);
Hashtable hashTable = handler.getTable();
out.println("<TABLE BORDER=2><CAPTION>教師信息表</CAPTION>");
out.println("<TR><TD>姓名</TD>" + "<TD>" +
(String)hashTable.get(new String("name")) + "</TD></TR>");
out.println("<TR><TD>學(xué)院</TD>" + "<TD>" +
(String)hashTable.get(new String("college"))+"</TD></TR>");
out.println("<TR><TD>電話</TD>" + "<TD>" +
(String)hashTable.get(new String("telephone")) + "</TD></TR>");
out.println("<TR><TD>備注</TD>" + "<TD>" +
(String)hashTable.get(new String("notes")) + "</TD></TR>");
out.println("</TABLE>");
%>
</BODY>
</HTML>
14.EJB的基本架構(gòu)
一個(gè)EJB包括三個(gè)部分:
Remote Interface 接口的代碼:
package Beans;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
public interface Add extends EJBObject
{
//some method declare
}
Home Interface 接口的代碼
package Beans;
import java.rmi.RemoteException;
import jaax.ejb.CreateException;
import javax.ejb.EJBHome;
public interface AddHome extends EJBHome
{
//some method declare
}
EJB類的代碼:
package Beans;
import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javx.ejb.SessionContext;
public class AddBean Implements SessionBean
{
//some method declare
}
15.如何校驗(yàn)數(shù)字型?
var re=/^\d{1,8}$|\.\d{1,2}$/;
var str=document.form1.all(i).value;
var r=str.match(re);
if (r==null)
{
sign=-4;
break;
}
else{
document.form1.all(i).value=parseFloat(str);
}
16.將一個(gè)鍵盤輸入的數(shù)字轉(zhuǎn)化成中文輸出
(例如:輸入:1234567 輸出:一百二拾三萬(wàn)四千五百六拾七)
用java語(yǔ)言實(shí)現(xiàn),,請(qǐng)編一段程序?qū)崿F(xiàn)!
public class Reader {
private String strNum;
private String strNumChFormat;
private String strNumTemp;
private int intNumLen;
private String strBegin;
public Reader(String strNum) {
this.strNum = strNum;
}
public boolean check(String strNum) {
boolean valid = false;
if (strNum.substring(0,1).equals("0")){
this.strNum = strNum.substring(1);
}
try {
new Double(strNum);
valid = true;
}
catch (NumberFormatException ex) {
System.out.println("Bad number format!");
}
return valid;
}
public void init() {
strNumChFormat = "";
intNumLen = strNum.length();
strNumTemp = strNum;
strNumTemp = strNumTemp.replace('1', '一');
strNumTemp = strNumTemp.replace('2', '二');
strNumTemp = strNumTemp.replace('3', '三');
strNumTemp = strNumTemp.replace('4', '四');
strNumTemp = strNumTemp.replace('5', '五');
strNumTemp = strNumTemp.replace('6', '六');
strNumTemp = strNumTemp.replace('7', '七');
strNumTemp = strNumTemp.replace('8', '八');
strNumTemp = strNumTemp.replace('9', '九');
strNumTemp = strNumTemp.replace('0', '零');
strNumTemp = strNumTemp.replace('.', '點(diǎn)');
strBegin = strNumTemp.substring(0, 1);
}
public String readNum() {
if (check(strNum)) {
init();
try {
for (int i = 1, j = 1, k = 1; i < intNumLen; i++) {
if (strNumTemp.charAt(intNumLen - 1) == '零' && i == 1) {
strNumChFormat = "位";
}
else if (strNumTemp.charAt(intNumLen - i) == '零' && j == 1) {
strNumChFormat = "位" + strNumChFormat;
}
else if (strNumTemp.charAt(intNumLen - i) == '點(diǎn)') {
j = 1;
k = 1;
strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
continue;
}
else {
strNumChFormat = strNumTemp.charAt(intNumLen - i) + strNumChFormat;
}
if (strNumTemp.charAt(intNumLen - i - 1) != '位' &&
strNumTemp.charAt(intNumLen - i - 1) != '零') {
if (j == 1 && i < intNumLen) {
strNumChFormat = '拾' + strNumChFormat;
}
else if (j == 2 && i < intNumLen) {
strNumChFormat = '百' + strNumChFormat;
}
else if (j == 3 && i < intNumLen) {
strNumChFormat = '千' + strNumChFormat;
}
}
if (j == 4 && i < intNumLen) {
j = 0;
}
if (k == 4 && i < intNumLen) {
strNumChFormat = '萬(wàn)' + strNumChFormat;
}
else if (k == 8 && i < intNumLen) {
k = 0;
strNumChFormat = '億' + strNumChFormat;
}
j++;
k++;
}
while (strNumChFormat.indexOf("位") != -1) {
strNumChFormat = strNumChFormat.replaceAll("位", " ");
}
if (strNumChFormat.substring(0, 2) == "一拾") {
strNumChFormat = strNumChFormat.substring(1, strNumChFormat.length());
}
if (strNumChFormat.indexOf("點(diǎn)") >= 0) {
String rebegin = strNumChFormat.substring(0,
strNumChFormat.indexOf("點(diǎn)"));
String relast = strNumChFormat.substring(strNumChFormat.indexOf("點(diǎn)"),
strNumChFormat.length());
for (int i = 1; i <= relast.length(); i++) {
relast = relast.replaceAll("拾", "");
relast = relast.replaceAll("百", "");
relast = relast.replaceAll("千", "");
relast = relast.replaceAll("萬(wàn)", "");
relast = relast.replaceAll("億", "");
}
strNumChFormat = rebegin + relast;
}
}
catch (ArrayIndexOutOfBoundsException ex) {
ex.printStackTrace();
}
catch (Exception ex) {
ex.printStackTrace();
}
int off = strNumChFormat.indexOf("點(diǎn)");
strNumChFormat = strBegin + strNumChFormat.substring(0);
}
else {
strNumChFormat = "";
}
return strNumChFormat;
}
public static void main(String args[]) {
try {
String number = args[0].toString();
System.out.println("The number is: " + number);
Reader reader = new Reader(number);
System.out.println("Output String: " + reader.readNum());
}
catch (Exception ex) {
System.out.println("Please input like that: javac Reader <number>");
}
}
}