
- Java Tutorial
- Java - Home
- Java - Overview
- Java - Environment Setup
- Java - Basic Syntax
- Java - Object & Classes
- Java - Constructors
- Java - Basic Datatypes
- Java - Variable Types
- Java - Modifier Types
- Java - Basic Operators
- Java - Loop Control
- Java - Decision Making
- Java - Numbers
- Java - Characters
- Java - Strings
- Java - Arrays
- Java - Date & Time
- Java - Regular Expressions
- Java - Methods
- Java - Files and I/O
- Java - Exceptions
- Java - Inner classes
- Java Object Oriented
- Java - Inheritance
- Java - Overriding
- Java - Polymorphism
- Java - Abstraction
- Java - Encapsulation
- Java - Interfaces
- Java - Packages
- Java Advanced
- Java - Data Structures
- Java - Collections
- Java - Generics
- Java - Serialization
- Java - Networking
- Java - Sending Email
- Java - Multithreading
- Java - Applet Basics
- Java - Documentation
- Java Useful Resources
- Java - Questions and Answers
- Java - Quick Guide
- Java - Useful Resources
- Java - Discussion
- Java - Examples
Java Program to Find sum of Series with n-th term as n^2 – (n-1)^2
To find the sum of such series, the Java program is as follows −
Example
public class Demo { static long my_val = 1000000007; public static long compute_val(long my_int){ return ((my_int % my_val) * (my_int % my_val)) % my_val; } public static void main(String[] args){ long my_int = 45687234; System.out.println("The computed value is "); System.out.print(compute_val(my_int)); } }
Output
The computed value is 335959495
A class named Demo defines a function named ‘compute_val’ that computes and returns the sum of a specific series. In the main function, the long integer is defined and the function is calling by passing this integer as the parameter. Relevant output is displayed on the console.
- Related Articles
- Find sum of Series with n-th term as n^2 - (n-1)^2 in C++
- Python Program for Find sum of Series with the n-th term as n^2 – (n-1)^2
- C/C++ Program to Find the sum of Series with the n-th term as n^2 – (n-1)^2
- C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
- Program to find N-th term of series 1, 2, 11, 12, 21… in C++
- Java Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ program to find the sum of the series 1 + 1/2^2 + 1/3^3 + …..+ 1/n^n
- C++ program to find n-th term of series 2, 10, 30, 68, 130 …
- Program to find N-th term of series 0, 0, 2, 1, 4, 2, 6, 3, 8…in C++
- C++ Programe to find n-th term in series 1 2 2 3 3 3 4
- Python Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- C++ Program to find the sum of a Series 1/1! + 2/2! + 3/3! + 4/4! + …… n/n!
- C++ program to find the sum of the series 1/1! + 2/2! + 3/3! + 4/4! +…….+ n/n!
- Program to find N-th term of series 2, 4, 3, 4, 15… in C++
- Program to find N-th term of series 0, 2,1, 3, 1, 5, 2, 7, 3...in C++

Advertisements