-3
        int stdCodes[] = new int[2];
        System.out.println("Enter 2 STD codes:");
        for (int i = 0;  i <2; i++) 
        {
            stdCodes[i] = sc.nextInt();
        }
        for (int i = 0;  i <2; i++) 
        {
           System.out.println(stdCodes[i]);
        }



 Enter 2 STD codes:
    01975
    01887
   
    output:
    1975
    1887
    

While entering std codes in SDA i entered std code with zero but why zero is not in values at time of display array?

amann
  • 1

2 Answers2

0

Since you declared the array as an int[], Java stores and outputs the result with just the most significant digits. You can store it as a string if you want to keep the 0, or format the output by concatenating "0" by hand before the stdCode

rikyeah
  • 1,896
  • 4
  • 11
  • 21
0

The leading zero will be omitted when your input string is parsed into integer. If you want to remain the leading zero you should choose the "String" data type.

Harry Lu
  • 34
  • 5