The output of this code will be '45'.

Explanation:

  • The variable x is initialized to the integer value 23456.
  • The toString() method is called on x, which converts it to a String representation: '23456'.
  • The substring(2,4) method is called on this String, which returns a new String containing the characters starting at index 2 (inclusive) and ending at index 4 (exclusive): '45'.
  • Finally, this String is printed to the console using the println() method.
Java String Substring Example: Extracting Characters from an Integer

原文地址: https://www.cveoy.top/t/topic/mXBp 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录