Skip to content
← Back to Community
how to run only specific file
Profile icon
sandiptikole

i added new file and it has main method and i want to run only that file. currently it is running only first added file which has main method

Voters
Profile icon
Superbanann
Profile icon
IshraqKhan
Profile icon
ShonHaskaj
Profile icon
TaegonHibbitts2
Profile icon
winter5oldier
Profile icon
Shree-NidhiNidh
Profile icon
rickyaw3
Profile icon
JackKelley9
Profile icon
yomnasultan
Profile icon
SuryanshChopra
Comments
hotnewtop
Profile icon
PiotrZdunski

in console type in: javac BestTimeToBuyStock.java
and then java BestTimeToBuyStock

image

Profile icon
abc3354

Hi !
Replit will run the Main class and in this class the main method will be called.
If you want to have two codes, you should create two repl

There is an other way but I don't think that it is a good practice (I do not know java very well)
You can call the main method of BestTimeToBuyStock class in the Main class
This not very clear so I made an example here

Main.java line 67

String empty[] = {}; BestTimeToBuyStock.main(empty);

Replit helper here !
If you found my answer helpful, you can upvote it :)
If my post answers the question, mark it as the answer with the check mark !

Profile icon
Zavexeon

Hi. Repl.it will always execute the main file first. Consider using a polygott repl.

Profile icon
Steven_The_GuyT

What do you mean by running not main method? or maybe:

public class Main { //main(paramater); OtherCode(); public static void main(String []args){ //code } public static void OtherCode(){ //code } }

You just call the function that you want, and comment out the functions that you don't want.