Arithmetic formulas in Java execution strings

Source: Internet
Author: User
Tags arithmetic

When implementing an arithmetic formula in a string, the following code is used:

 Public Static string Stringfinalresult (string original) {              try  {                    = (string) jse.eval ( original);                   return temp;               Catch (Exception t) {                    returnnull;              }  }  

The console output is null after the function is called

The code should be modified to resemble the following:

 Public Static string Stringfinalresult (string original) {              try  {                    = jse.eval (original);                  =temp.tostring ();                   return result;               Catch (Exception t) {                    returnnull;              }  }  

The reason for the error is that Jse.eval () cannot force the type to be converted to string format, so the program executes a catch statement.

I found it by modifying the return value in the Catch statement.

Arithmetic formulas in the Java execution string

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.