Advertisement
sergAccount

Untitled

Oct 4th, 2020
1,109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.04 KB | None | 0 0
  1. /*
  2.  * To change this license header, choose License Headers in Project Properties.
  3.  * To change this template file, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. package app51;
  7.  
  8. /**
  9.  *
  10.  * @author Admin
  11.  */
  12. public class App51 {    
  13.     // Метод, который вычисляет сумму чисел от n до m включительно
  14.     // n,m - целые числа
  15.     // У метода должны быть два параметра типа int
  16.     // Метод должен возвращать значение типа int  
  17.     public static int calcSum(int n, int m){
  18.         int result = 0;
  19.         for(int i=n; i<=m; i++){
  20.             result = result + i; // result += i;
  21.         }
  22.         return result;        
  23.     }      
  24.     public static void main(String[] args) {
  25.         // TODO code application logic here
  26.         int res = calcSum(1, 3); // 1 + 2 + 3
  27.         System.out.println(res);
  28.        
  29.         res = calcSum(1, 10);
  30.         System.out.println(res);
  31.     }    
  32. }
  33.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement