Hands-on benefits.
Enter an expression without parentheses, the number is less than 0-9, the output evaluates, and all the intermediate results are turned into shaping.
Example: Input: 3+8x2/9-2
Output: 2
/*** Input A calculate string, calcuate the value * The number between 0-9 * round the middle Vlaue to int * */ Public Static voidMain (string[] args) {//8*6+2-6/3*6+2String Cal;//=new Scanner (system.in). nextline ();Cal= "8*6+2-6/3*6+2"; String[] Car=Newstring[cal.length ()]; for(inti = 0; i < car.length; i++) {Car[i]=""+Cal.charat (i); } System.err.println (car); //Do * and/ for(inti = 0; i < car.length; i++) { if(Car[i].equals ("*") ) {Car[i+1]= "" + (Integer.parseint (car[i-1)) * Integer.parseint (car[i+1])); Car[i-1]= ""; Car[i]=""; }Else if(Car[i].equals ("/") ) {Car[i+1]= "" + (Integer) (Integer.parseint (car[i-1])/Integer.parseint (car[i+1])); Car[i-1]= ""; Car[i]=""; } Else { Continue; } } //Do + and- intIndex=0; for(inti = 0; i < car.length; i++) {Index=i; if(Car[i].equals ("+")) { while(Car[++index].equals ("") ) {} Car[index]= "" + (Integer.parseint (car[i-1]) +Integer.parseint (Car[index])); Car[i-1]= ""; Car[i]=""; }Else if(Car[i].equals ("-")) { while(Car[++index].equals ("") ) {} Car[index]= "" + (Integer.parseint (car[i-1])-Integer.parseint (Car[index])); Car[i-1]= ""; Car[i]=""; } Else { Continue; }} System.err.println (Cal+ "=" +car[car.length-1]); }
[Java] Enter an arithmetic expression to output the result