ex:
輸入1 10
程式會從1開始累加到10

----------------------------------------------------------
//程式開始
class Neo_1_1{
public static void main(String args[]){
if (args.length ==2 ){
int init = Integer.parseInt(args[0]);
int cond = Integer.parseInt(args[1]);
if(init > cond){
System.out.println("數字較小的必須放在前面");
return;
}
int count = 0;
for(int i = init ; i <=cond ; i++){
count = count + i ;
}
System.out.println("由"+ init +"加到"+cond+"的值為 : "+count);
}
else{
System.out.println("請輸入兩個數值");
return;
}
}
}
//結束
---------------------------------------------------------------------
arrow
arrow
    全站熱搜

    Neo Chao 發表在 痞客邦 留言(0) 人氣()