---
# System prepended metadata

title: 基礎程式設計a056

---

##### tags: `重點筆記`

# 基礎程式設計a056

```c=
public class w1  
2	{ 
3	  static void addten (String args[]) 
4	  {  
5	    int sum  = 0; 
6	    int no[] = {1,2,3,4,5,6,7,8,9,10}; 
7	     
8	    // 陣列由零開始，所以i的初值為0，末值為9，共10個 
9	    // 否則會丟出ArrayIndexOutOfBoundsException 
10	    for (int i = 0; i < 10; i++) 
11	    {  
12	      sum = sum + no[i]; 
13	      System.out.println ("總數=" + sum); 
14	    } 
15	  }  
16	 
17	  // int[] args 改成 String[] args 
18	  public static void main (String[] args)  
19	  {  
20	    // addten 原函數定義裡需要參數... addten ()的呼叫，改成 addten (args) 
21	    addten (args); 
22	  } 
23	} 
開新視窗(view plain) | 列印(print) | ?
```

```c=


public class w1
{
static void addten(String args[])
{ int sum=0;
int no[]={1,2,3,4,5,6,7,8,9,10};
for (int i = 1; i <=10; i++)
{ sum = sum + no[i];
System.out.println("總數="+sum);}}

public static void main(int[] args)
{ addten();}}

執行結果：
addten(java.lang.String[]) in w1 cannot be applied to ()
addten();
1 error