class Test { int sum(int[] date){ int r=0; int i; for(i=0; i<date.length; i++) r += date[i]; return r; } }
public class sample34{ public static void main(String[] args) { Test test =new Test(); int[] date1 = new int[]{1,2,3,4,5}; int result; result=test.sum(date1); System.out.println(result); } } これで15が返ってくる理由教えてください。 私の考えはsum(int[] date)ここに{1,2,3,4,5}を入れるわけですよね? でdate.lengthとなっているから、その個数5だと思うんですけど すいません意味不明で・・・