菜鸟请教高手指点

abuiff 2007-01-10 10:16:09
想做一题连接字符串或者数字的,也就是AA+BB=AABB或1+2=12的,自己做了一个,感觉很麻烦,太复杂了,所以想请教一下高手有没有什么简单的写法,在此附上我的代码,希望高手能帮我写一个简单的程序,让我学习学习:
package ks;
import java.awt.*;
import java.awt.event.*;

public class Text implements ActionListener {
TextField t1 = new TextField();
TextField t2 = new TextField();
TextField t3 = new TextField();
Button b1 = new Button("连接字符串");

public Text() {
}
public static void main(String args[])
{
Text t1 = new Text();
t1.init();
}

/**
* actionPerformed
*
* @param e ActionEvent
*/
public void init(){
Frame f1 = new Frame();
f1.setLayout(new BorderLayout(10,20));

f1.add("North",t1);
f1.add("Center",t2);
f1.add("South",b1);
f1.add("East",t3);
b1.addActionListener(this);
f1.show();

}

public void actionPerformed(ActionEvent e) {
String t4 = "";
t4 = t1.getText().concat(t2.getText());
t3.setText(t4);
StringBuffer ss = new StringBuffer();
ss.append(11);
System.out.println(ss);
}
}

class GetInt
{
public int getInt(String str)
{

try
{

if(str.length()==0)
return -1;
for(int i=0;i<str.length();i++)
{
if(str.charAt(i)<'0'||str.charAt(i)>'9')
return -1;

}
return 1;
}
catch(Exception e)
{
return -1;
}

}
}
class Input
{
public static void main(String[] args)
{
GetInt get=new GetInt();

int num=get.getInt(args[0]);
if(num==1)
{
System.out.println(Integer.parseInt(args[0]) + Integer.parseInt(args[1]));
}
else{
System.out.println(args[0].concat(args[1]));
}
}
}

...全文
195 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
ithuo 2007-01-26
  • 打赏
  • 举报
回复
用vector类可以实现吧
lanseliuying 2007-01-11
  • 打赏
  • 举报
回复
乱乱的。怎么两个main啊?
连接字符串或者是数字直接转换成String型的,用连接符"+"不就行了。
如:
String a="1",b="2";
String c=a+b;

50,523

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧