java.util.scanner - Run Java Console Input as Statement -


i writing command-line matrix manipulation tool in java, , wondering if possible run java statements through console input.

i thinking of using java.util.scanner object since that's i'm using rest of application, open solution.

here copy of tool's application class, can see mean:

package projects.matrix.main; import static java.lang.system.*; import java.util.scanner; import projects.matrix.util.matrixtool; /**  * matrix :: application class matrix toolset.   * @author  toner  * @version may 28 2015  * @since   1.8  **/ public class marixapp {     public static void main (string [] args) {     out.println("****************************** start*****************"        + "*************\n");         runcommandline();         out.println("******************************  end  *****************"           + "*************\n");     }      /**      * matrix.main :: runcommandline runs loop command line       * @param   none      * @return  none      **/     public static void runcommandline () {         // method vars         scanner scanner = new scanner(in);         matrixtool matrixtool = new matrixtool();         int[][] matrix1 = new int[0][0];         int[][] matrix2 = new int[0][0];         int[][] resultmatrix = new int[0][0];         string command = "";         int executerret = 0;          // welcome prints         out.println("[!] welcome toner's matrix tool command-line");         out.println("[!] enter 'help' view available commands\n");          // commmand-line loop         {             out.print(" [?] >> ");             command = scanner.nextline();             executerret = executecmd(command);         } while (executerret != -1);     }      /**      * matrix.main :: executecmd executes command passed runcommandline      * @param   cmd         : string      * @return  returncode  : int      **/     public static int executecmd (string cmd) {         // method vars         scanner scanner = new scanner(in);         matrixtool matrixtool = new matrixtool();         int returncode = 0;          // command executer         switch (cmd) {             case "help" :              case "help" :                  out.println("\n"                     + "  [%]    add        divide           "                     + "multiply   print"                     + "  [%]    runjava    substract  setmtrx    "                     + "setmtrx1   setmtrx2"                     + "  [%]    transpose  runops     reset      "                     + "exit\n");                 break;             // rest of commands go here         }     } } 

regards.

if running console input java statements, mean taking exact input console , run inside application, need compile , run them. can using compiler api


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -