I'm starting in java, I just had one class. So I'm doing a program to add the items to an array, and have to use method. This is my code.
Main:
package exercicio3e4;
public class Principal {
public static void main(String[] args) {
Somar x;
x= new Somar();
x.y={1,4,6,8,1};
x.calcular();
}
}
Add:
package exercicio3e4;
public class Somar {
int[] y;
void calcular() {
int i = y.length;
int total=0;
while (i >= 0) {
i--;
total = total + y[i];
}
System.out.println("Soma da array: " + total);
}
}