0

I have a java class which includes a method called kleiner. I want to call it inside the shell (for example kleiner 3 4). Here is the code below:

package premier;

public class HelloWorld {
public static void kleiner(int a, int b) {
    if (a < b)
        System.out.println(a);
    else
        System.out.println(b);
}

public static void main(String[] args) {
    // TODO Auto-generated method stub
    System.out.println("Hello world");

    kleiner(3, 4);

}

}
Grant Foster
  • 722
  • 2
  • 11
  • 21
  • https://docs.oracle.com/javase/tutorial/essential/environment/cmdLineArgs.html – Reimeus Oct 26 '18 at 20:47
  • 1
    That's what `args` is for in the main method. If you add `System.out.println(args)` and call `java HelloWorld 1 2` you'll get the idea of how it works – Krease Oct 26 '18 at 20:54
  • Can you use jshell? – Dane White Oct 26 '18 at 20:59
  • If you run `java premier.HelloWorld`, the `kleiner` method *is* called with parameters `3` and `4`, so what is your question? Perhaps re-phrase question to make it clearer. – Andreas Oct 26 '18 at 21:04

1 Answers1

0

Please follow below steps and you should able to run program from batch script.

  1. Compile programm - javac HelloWorld.java -d . it will generate HelloWorld.class class file in package directory which can we invoke from command line.
  2. run programm with java premier.HelloWorld

so if you put both the command in single bat file and click on the file. it will give output.

File name - HelloWorld.bat copy these 2 lines in file content.

javac HelloWorld.java -d .
java premier.HelloWorld

Hope it will help you.

alfunx
  • 3,080
  • 1
  • 12
  • 23