Write a function that will return the total of the following
Write a function that will return the total of the following statement
1*100 + 2*99 + 3*98 + ....+ 99*2 + 100*1
public int fun() {
}
Solution
TestFun.java
public class TestFun {
public static void main(String[] args) {
new TestFun();
}
public TestFun(){
int result = fun();
System.out.println(\"The total is \"+result);
}
public int fun() {
int total = 0;
for(int i=1; i<=100; i++){
for(int j=100; j>=1; j--){
total = total + i *j;
}
}
return total;
}
}
Output:
The total is 25502500
