+ 1

How can we write sum of number with double and for each loop???

code

29th Nov 2017, 3:53 PM
saman hoseini
saman hoseini - avatar
4 Answers
+ 5
This is taught in the course
29th Nov 2017, 4:00 PM
Rrestoring faith
Rrestoring faith - avatar
+ 3
Since this is a lesson, here's my input: 1. What does t stand for? Use variable names that describe their function or use the standard i for iteration. In this situation, I'd probably use num instead of t. 2. Always use proper formatting and spacing. 3. Instead of "sum=sum+t;", use "sum += t;"
29th Nov 2017, 4:04 PM
AgentSmith
+ 1
we can use this code public class Program { public static void main(String[] args) { double [ ] number = {50.76,76.009,98.0908,104.0065708,117.45609,120.65466}; double sum=0; for (double t: number ) { sum=sum+t; System.out.println(sum); } } }
29th Nov 2017, 3:54 PM
saman hoseini
saman hoseini - avatar
0
yeah yeah I know
29th Nov 2017, 5:50 PM
saman hoseini
saman hoseini - avatar