Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

class main is public, should be declared in a file named main.java

+3 votes
asked Oct 1, 2022 by Shubham Dhatwalia (150 points)
import java.util.Scanner;

public class function

{

    public static void printMyName(String name){

        System.out.print(name);

        return;

    }

public static void main(String[] args) {

Scanner sc = new Scanner(System.in);

String name = sc.nextLine();

printMyName(name);

}

}

1 Answer

0 votes
answered Oct 2, 2022 by Peter Minarik (86,180 points)

Call your class Main, not function. In Java, your class name and file name must match. The default file name is  Main.java, hence your class should have the same name.

Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and and receive answers from other members of the community.
...