Advertisement
CR7CR7

simplePrint

Oct 6th, 2022
671
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.38 KB | None | 0 0
  1. public static int sum(int i1, int i2) {
  2.  2 int result = 0;
  3.  3 for (int i = i1; i <= i2; i++)
  4.  4 result += i;
  5.  5
  6.  6 return result;
  7.  7 }
  8.  8
  9.  9 public static void main(String[] args) {
  10. 10 System.out.println("Sum from 1 to 10 is " + sum(1, 10));
  11. 11 System.out.println("Sum from 20 to 37 is " + sum(20, 37));
  12. 12 System.out.println("Sum from 35 to 49 is " + sum(35, 49));
  13. 13 }
  14.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement