-2
 public class Main {
    public static void main(String args[]) throws IOException {
      Scanner sc=new Scanner(System.in); 
           int t=sc.nextInt();
        while(t-->0){
          int n=sc.nextInt();
          int k=sc.nextInt();
          int[] arr=new int[n];
          for(int i=0;i<n;i++){
            arr[i]=sc.nextInt();
          }
          rotation(0,n-k-1,arr);
           rotation(n-k,n-1,arr);
        // rotation(0,n-1,arr);
          int temp;
          for(int i=n-1,j=0;j<i;i--,j++)
          {
             temp=arr[j];
             arr[j]=arr[i];
             arr[i]=temp;
          }
         // for(int i=0;i<n;i++){
         //  System.out.print(arr[i]);
         //  System.out.print(" ");
         // }
         System.out.println(Arrays.toString(arr));
         
        }
        }
        public static void rotation(int start,int end,int[] arr)
        {
          int temp;
          for(int i=end,j=start;j<i;i--,j++)
          {
             temp=arr[start];
             arr[start]=arr[end];
             arr[end]=temp;
          }
          
          
        }
      

    }

  

These are the constraints to be taken care of 1<=T<=20

1<=N<=10^5

0<=K<=10^6

0<=A[i]<=10^6

Input Format: The first line contains an integer T denoting the number of test cases. Each test case consists of two lines. The first line contains N , number of elements in the array and K number of steps. The Second line contains N space-separated integers.

Output Format:For each test case on a new line, print the rotated array.

msanford
  • 11,803
  • 11
  • 66
  • 93
  • 1
    Specifying the language with a tag is useful, that way people who care about [tag:java] will see it. That said, what is the _specific error_ you get? Because when I run it, I get `cannot find symbol Scanner sc=new Scanner` because you're missing an import. Maybe that's the problem, or maybe it's just because you didn't paste it into the question... please click edit on your question and add details. – msanford Jul 11 '20 at 15:15
  • Does this answer your question? [What does a "Cannot find symbol" or "Cannot resolve symbol" error mean?](https://stackoverflow.com/questions/25706216/what-does-a-cannot-find-symbol-or-cannot-resolve-symbol-error-mean) – msanford Jul 11 '20 at 15:23

2 Answers2

1

First of all, the code doesn't compile. Look at the compiler errors:

Main.java:2: error: cannot find symbol
    public static void main(String args[]) throws IOException {
                                                  ^
  symbol:   class IOException
  location: class Main
Main.java:3: error: cannot find symbol
      Scanner sc=new Scanner(System.in); 
      ^
  symbol:   class Scanner
  location: class Main
Main.java:3: error: cannot find symbol
      Scanner sc=new Scanner(System.in); 
                     ^
  symbol:   class Scanner
  location: class Main
Main.java:26: error: cannot find symbol
         System.out.println(Arrays.toString(arr));
                            ^
  symbol:   variable Arrays
  location: class Main
4 errors
error: compilation failed

What does cannot find symbol mean? In this case it means, the compiler doesn't know, what Scanner, IOException and Arrays are. You have to import these classes: Add following before public class Main:

import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

Now you should be able to compile the code.

JCWasmx86
  • 3,473
  • 2
  • 11
  • 29
  • I have included the imports and my program gives correct output. The problem is when I try to submit my code on the coding platform it's giving me a runtime time error message and it's not accepting my code. Whereas when I execute the code on my machine I am not getting any such error and output is correct. – dilshad preet Jul 11 '20 at 16:08
  • What is the "runtime time error message"? – JCWasmx86 Jul 11 '20 at 17:04
-2

May be changing the class name will execute this code.bcoz I think "Main" is keyword and we can't use it.

  • 2
    Hi, welcome to Stack Overflow. This is not a useful answer (and it's incorrect) and is better suited to being a comment. When you have enough reputation, you'll be able to post comments. Thanks. – msanford Jul 11 '20 at 15:31
  • Having a class called `Main` is completely legal. – Dorian Gray Jul 11 '20 at 16:12