3

Employee("Helen",16000,1965,08,03),compiler is throwing the error that integer number is too large for value : 08 but compiler has no problem with value 11 or just 8.

      import java.util.*;
      class Employee{
          private String name;
          private double salary;
          private Date hireDay;

              public Employee(String n, double s,int year, int month, int day){
                  name = n;
                  salary = s;
                  GregorianCalendar calendar = new GregorianCalendar(year,month-1,day);
                  hireDay = calendar.getTime();
              }
              public String getName(){
                  return name; 
              }   
              public double getSalary(){
                  return salary;
              }   
              public Date getHireDay(){
                  return hireDay; 
              }   

              public void raiseSalary(double byPercent){
                  double raise = salary * byPercent / 100;
                  salary += raise;

              }

      }

      public class EmployeeTest{
          public static void main(String[] args){

         Employee[] staff = new Employee[3];
          staff[0] = new Employee("Jack",15000,1992,03,07);
          staff[1] = new Employee("James",18000,1987,05,02);
    >>    staff[2] = new Employee("Helen",16000,1965,08,03);

// This is the problem.When I pass 08 it throws an error when I pass 08 or some two digit number it is find }

Output :

    [shadow@localhost java]$ javac EmployeeTest.java 
    EmployeeTest.java:37: error: integer number too large: 08
        staff[2] = new Employee("Helen",16000,1965,08,03);
                                                   ^
    1 error
    [shadow@localhost java]$
0

1 Answer 1

3

It's because, in Java, numbers that start with a leading 0 (like your 08) are treated as octal (base 8). And there is no 8 in octal.

(By definition octal only uses the digits 0-7)

As an experiment, you can try 07 or 011 and see that they work, or try 08 or 09 and see that they don't work.

Sign up to request clarification or add additional context in comments.

2 Comments

But I passed the data type as int. Why java is treating 08 as octal ?
in java a leading 0 is understood to be an octal digit

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.