问题: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字符串的常用操作问题这个问题有好的意见或
建议,请留言
|