java - For a console calculator program, how to split an array of strings (that are numbers) into an array of strings -


i'm writing command line application of calculator in java. need able (as per program requirements) split array of strings (6+3) array of strings? how done? know can use split method, not sure how work perform math them?

on side note: application, how make program accept variety of different lengths of strings perform math them?

public class calculator { //public string input ="foo";  public static void main(string[] args) {     string input = ""; // initalize string     boolean ison = true; // used while loop...when false, program exit.     string exitcommand = "exit"; // exit command        system.out.print("enter math problem"); // dummy test     scanner keyboard = new scanner(system.in);     //input = keyboard.nextline();     string[] token = input.split(("(?<=[-+*/])|(?=[-+*/])"));     while (ison) {         (int = 0; < token.length; i++) {             //system.out.println(token[i]);             double d = double.parsedouble(keyboard.nextline()); //this causes error             //string[] token = d.split(("(?<=[-+*/])|(?=[-+*/])"));             //input = keyboard.nextline();              if (input.equalsignorecase(exitcommand)) {                 // if user enters exit(ignored case) boolean goes false, closing application                 ison = false;             }             system.out.print(token[0] + d); // shows math problem(which end of coding should show             //answer entered math problem.          }       } } public void validoperator() {     arraylist<string> operator = new arraylist<string>();     operator.add("+");     operator.add("-");     operator.add("*");     operator.add("/");  } public void validoperands(){     arraylist<string> operand = new arraylist<string>();     operand.add("0");     operand.add("1");     operand.add("2");     operand.add("3");     operand.add("4");     operand.add("5");     operand.add("6");     operand.add("7");     operand.add("8");     operand.add("9"); } 

}

that am. cannot figure out how parse expression. can enter single number, not expression , have math "math".

little nebulous, assuming trying separate operators numbers

new string("6+3").split("\+") should give 2 numbers.

split takes regular expression, put operators you're handling in regex , numbers


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -