Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6999904

int a = Integer.parseInt(args[0]) does not accept strings with "+" such as "+5"

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 6u22
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :


      ADDITIONAL OS VERSION INFORMATION :
      Windows XP

      A DESCRIPTION OF THE PROBLEM :
       int a = Integer.parseInt(args[0]) does not accept strings with "+" such as "+5"

      I want to convert a string with a "+" in front of an integer into an "int" value using parseInt().. But strings such as "+35" cause a number format exception because of the "+" sign. This is absurd because "+35" as a number, is an integer value, just as "35" is. Negative signs are accepted by parseInt(), but not positive signs.



      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      Exception in thread "main" java.lang.NumberFormatException: For input string "+9"

      REPRODUCIBILITY :
      This bug can be reproduced always.

      ---------- BEGIN SOURCE ----------
      public class EnterValues
      {
        public static void main(String[] args) {
          
          int a = Integer.parseInt(args[0]);
          int b = Integer.parseInt(args[1]);
         
          System.out.println(" you have entered these values : " + a + " and " + b);
         
          System.out.println(" area of a rectange is : " + a*b);
        }
      }
      ---------- END SOURCE ----------

            mduigou Mike Duigou
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: