![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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.
Advertisements