-4

So I am new to Java and just copy and paste this course in Netbeans after making a new project. This should run but is not running because no main class is found.

package java.tutorial;

/**
 *
 * @author Admin
 */
public class JavaTutorial {
    
    public static int[] rotateArray(int[] arr, int k)
    {
        // TODO code application logic here
        for(int i=0;i<k%arr.length;i++)
        {
            int temp=arr[arr.length-1];
            for(int j=arr.length-1;j>0;j--){           
                arr[j]= arr[j-1];
            }
            arr[0]= temp;
        }
        return arr;
    }
}
AmrDeveloper
  • 3,826
  • 1
  • 21
  • 30
  • 1
    What do you understand from that error message? Speaking of, please provide the entire error output. – AMC Oct 13 '20 at 01:43
  • Can you tell us in plain English what you expect to happen when you run this code? – tgdavies Oct 13 '20 at 02:02
  • 1
    Does this answer your question? ["Error: Main method not found in class MyClass, please define the main method as..."](https://stackoverflow.com/questions/5407250/error-main-method-not-found-in-class-myclass-please-define-the-main-method-as) – Scratte Oct 13 '20 at 10:29
  • Also, see [Error :: Main method not found in class](https://stackoverflow.com/questions/44086525/error-main-method-not-found-in-class) – Scratte Oct 13 '20 at 10:29

2 Answers2

0

Your application needs a main method as a starting point in this case.

package java.tutorial;
import java.util.*;
public class JavaTutorial{
    // Include a main method and make method calls inside it.
    public static void main (String[] args){
        int[] arr = new int[]{1,2,3,4};
        System.out.println(Arrays.toString(rotateArray(arr, 3)));
        // Output: [2, 3, 4, 1]
    }
    public static int[] rotateArray(int[] arr, int k){
    // TODO code application logic here
        for(int i=0;i<k%arr.length;i++){
            int temp=arr[arr.length-1];
            for(int j=arr.length-1;j>0;j--){           
                arr[j]= arr[j-1];
            }
            arr[0]= temp;
        }
        return arr;
    }
}
Hung Vu
  • 443
  • 3
  • 15
0

Any Java project must have main method to start so your code should have one and call your rotateArray inside it

public class Solution {

    public static void main(String[] args) {
        int input[] = {1, 2, 3, 4, 5, 6};
        int order = 3;
        int result[] = rotateArray(input, order);
    }

    public static int[] rotateArray(int[] arr, int k)
    {
        // TODO code application logic here
        for(int i=0;i<k%arr.length;i++)
        {
            int temp=arr[arr.length-1];
            for(int j=arr.length-1;j>0;j--){
                arr[j]= arr[j-1];
            }
            arr[0]= temp;
        }
        return arr;
    }
}
AmrDeveloper
  • 3,826
  • 1
  • 21
  • 30