hello, like in the title I can't answer this question by myself or searching online.
i create this beginner program, for learning:
- how many elements do you want to operate? x
-write down the x elements, i will show you sum, subtraction product and division.
like 10,3,2
sum of them is = 10 + 3 + 2 = 15
subtraction is = 10 - 3 - 2 = 5
product = 10 * 3 * 2 = 60
division = 10 / 3 / 2 = 1 (int)
i did sum like this:
System.out.print("How many elements you want to treat? ");
int elementi = input.nextInt();
int[] array = new int[elementi];
System.out.println("Enter the elements to treat: ");
for (int i = 0; i < elementi; i++)
{
array[i]=input.nextInt();
}
System.out.println("arraylength is: " + array.length);
int sum = 0;
for (int i = 0; i < array.length; i++)
{
sum = sum + array[i];
}
but i can't understand the cycle for subtraction product and division.
thanks for your help