ในการหาผลรวมของอนุกรมดังกล่าว โปรแกรม Java มีดังต่อไปนี้ −
ตัวอย่าง
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));
}
} ผลลัพธ์
The computed value is 335959495
คลาสชื่อ Demo กำหนดฟังก์ชันชื่อ 'compute_val' ที่คำนวณและส่งคืนผลรวมของชุดข้อมูลที่ระบุ ในฟังก์ชันหลัก กำหนดจำนวนเต็มแบบยาวและฟังก์ชันกำลังเรียกใช้การข้ามจำนวนเต็มนี้เป็นพารามิเตอร์ เอาต์พุตที่เกี่ยวข้องจะแสดงบนคอนโซล