Calculating the sum of all odd array indexes

后端 未结 5 952
予麋鹿
予麋鹿 2021-01-24 19:00

I want to calculate the sum of all odd array indexes, but I\'m having some trouble finding the right way to do it.

Here\'s my code so far:

    String id         


        
5条回答
  •  滥情空心
    2021-01-24 19:43

    String id = "9506265088085";
    int[] intArray = new int[strArray.length];
    int sum = 0;
    
    for (int i = 1; i < id.length(); i+=2) {
            sum += Integer.parseInt(String.valueOf(id.charAt(i)));
        } 
    
        System.out.println(sum);
    

提交回复
热议问题