雞婆一下,總整理,還有幾種輸入條件驗證未考慮,自己補充一下吧!!
public class Example {
private static void square(double a){
System.out.println("平方 ===>"+Math.sqrt(a));
}
private static void cube(double a){
System.out.println("三次方 ===>"+Math.pow(a,3));
}
private static boolean checkNum(String num){
String chkChr = "-.0123456789";
for(int i = 0 ; i < num.length() ; i++){
if(chkChr.indexOf(num.charAt(i)) == -1){
System.out.println("Plz input Number!!");
return false;
}
}
return true;
}
public static void main(String[] args) {
if(args.length > 0 && args[0] != null){
if(checkNum(args[0])){
double input = Double.parseDouble(args[0]);
Example.square(input);
Example.cube(input);
}
}else{
System.out.println("Runs With : java Example xxx , xxx:input number");
}
}
}
|