您当前的位置: 百科371电脑/网络JAVA相关 → 电脑/网络内容 退出登录 用户管理 用户注册
本类热门文章
相关文章
中原建材网
JAVA字符串的常用操作问题

减小字体 增大字体

问题:JAVA字符串的常用操作问题  

/**
* @author 作者:***
* @version 创建时间:2008-4-30 下午10:51:08
* 功能说明:
* @version 修改时间:2008-4-30
* 修改原因:
*/
class Validate
{
public boolean isInteger(String te){
try{
Integer.parseInt(te);
return true;
}catch(NumberFormatException e){
return false;
}
}
}

public class M
{
public static void main(String[]args){
Integer a, b;
char op;
Validate n = new Validate();
op = args[1].charAt(0);
if((args.length==3)&& n.isInteger(args[0])&&n.isInteger(args[2]))
{
a = Integer.parseInt(args[0]);
b = Integer.parseInt(args[2]);
switch(op){
case '+': System.out.format("%d + %d = %d", a, b, a+b); break;
case '-': System.out.format("%d - %d = %d", a, b, a-b); break;
case '*': System.out.format("%d * %d = %d", a, b, a*b); break;
case '/': {
if(b==0){
System.out.println("Error Should not be devided by 0");
break;
}
else{
System.out.format("%d / %d = %d", a, b, a/b); break;
}
}
default: System.out.println("Operater ERROR");
}
}
else{
System.out.println("Arguments Error");
}


}
}


自己好好研究哦,不会可以给你注释。
看不懂问我

如果你对JAVA字符串的常用操作问题这个问题有好的意见或 建议,请留言
[] [返回上一页] [打 印]
电脑/网络评论 (评论内容只代表网友观点,与本站立场无关!)

用户名: 查看更多评论

分 值:100分 85分 70分 55分 40分 25分 10分 0分

内 容:

         (注“”为必填内容。) 验证码: 验证码,看不清楚?请点击刷新验证码

中原建材网 简单版 站长QQ:382546553