+ 1
How can we write sum of number with double and for each loop???
code
4 Answers
+ 5
This is taught in the course
+ 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;"
+ 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);
}
}
}
0
yeah yeah I know