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”的函式,該函式計算並返回特定級數的和。在 main 函式中定義一個 long 整數,並透過將該整數作為引數傳遞呼叫該函式。相關的輸出顯示在控制檯。