Advertisement
Guest User

Untitled

a guest
Nov 16th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.53 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Zadanie2a {
  4.     public static void main(String[] args) {
  5.         Scanner sc = new Scanner(System.in);
  6.         System.out.print("Prosze podac liczbe N: ");
  7.         int N = sc.nextInt();
  8.         System.out.println("Suma ciagu f(N) = " +sum(N));
  9.     }
  10.  
  11.     static int sum(int a){
  12.         int[] tab = new int[a+1];
  13.         tab[1] = 1;
  14.         tab[2] = 3;
  15.         for(int i = 3; i<tab.length; i++){
  16.             tab[i] = tab[i-1]+i;
  17.         }
  18.         return tab[tab.length-1];
  19.     }
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement