Java 这个代码是什么意思?实施

Java 这个代码是什么意思?实施,java,implementation,Java,Implementation,有人能解释一下这个公式的作用吗 import java.io.*; import java.util.*; import java.text.*; import java.math.*; import java.util.regex.*; public class Solution{ public static void main(String[] args) { Scanner in = new Scanner(System.in); int n =

有人能解释一下这个公式的作用吗

import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution{
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int k = in.nextInt();
        int q = in.nextInt();
        int[] a = new int[n];
        for(int a_i=0; a_i < n; a_i++){
            a[a_i] = in.nextInt();
        }
        for(int a0 = 0; a0 < q; a0++){
            int m = in.nextInt();
            System.out.println(a[((m-k)%n+n)%n]);
        }
    }
}
import java.io.*;
导入java.util.*;
导入java.text.*;
导入java.math.*;
导入java.util.regex.*;
公共类解决方案{
公共静态void main(字符串[]args){
扫描仪输入=新扫描仪(系统输入);
int n=in.nextInt();
int k=in.nextInt();
int q=in.nextInt();
int[]a=新的int[n];
for(int a_i=0;a_i
导入java.io.*//导入java.io包中的所有类,与下面的所有导入语句相同。
导入java.util.*;
导入java.text.*;
导入java.math.*;
导入java.util.regex.*;
公共类解决方案{//创建名为Solution的类
公共静态void main(String[]args){//main methid,程序开始执行的地方。
Scanner in=new Scanner(System.in);//Scanner是一个类,您可以使用它通过控制台从用户获取输入。因此,您在这里创建了一个“Scanner”类的对象。
int n=in.nextInt();//这将通过控制台从用户获取下一个int类型
int k=in.nextInt();//这将通过控制台从用户获取下一个int类型
int q=in.nextInt();//这将通过控制台从用户获取下一个int类型
int[]a=new int[n];//创建大小为n的数组。这意味着您可以在数组中存储n个值。请记住,n是用户给定的数字。如果用户说5,即您可以在数组中存储5个值。
对于(int a_i=0;a_i

a[((m-k)%n+n)%n])表示1st m-k-->结果%n(给您提示)-->+n-->%n=result。最后将给出一个[结果]。如果结果是一个有效的索引,那么您将从数组中获得有效的结果,如果不是,这意味着如果结果大于数组的大小,您将获得ArrayIndexOutOfBoundsException

如果您感到困惑,这里是问题的链接:
import java.io.*;//importing all the classes in java.io package and same with all below import statements.
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;

public class Solution{ //creating a class named Solution
    public static void main(String[] args) { //main methid where the execution of the program begins.
        Scanner in = new Scanner(System.in);//scanner is class by using which you can take the input from the user through the console. so you are creating an object of "Scanner" class here.
        int n = in.nextInt();//this will take the next int type from the user through the console
        int k = in.nextInt();//this will take the next int type from the user through the console
        int q = in.nextInt();//this will take the next int type from the user through the console
        int[] a = new int[n];//creating an array of size n.this means you can store n number of values in the array.rememeber n is the  number given by user.if user says 5 i.e you can store 5 values in the array. 
        for(int a_i=0; a_i < n; a_i++){//itrating over the n value
            a[a_i] = in.nextInt();//taking the integer value from the user and pusing in to the 'a_i' index
        }
        for(int a0 = 0; a0 < q; a0++){//iterating till value q
            int m = in.nextInt();//taking the m value from the use
            System.out.println(a[((m-k)%n+n)%n]);//performing mathematical operation

        }
    }
}