S
S
Sergey Sergey2021-05-13 14:06:32
Java
Sergey Sergey, 2021-05-13 14:06:32

Why does it return zero year if set is used?

public class NewCalendar {
      private int year;
      public int getYear(){
          return year;
        }
      public void setYear(int y){
          year = y;
      }
    int year(){
        for(year=2021; year < 2070; year++) {
            System.out.println("  " + year);
        // Подгон февраля под високосный год
        if (year % 4 == 0)  {
            /*days[1] = 28*/
             System.out.println("Високосный год ");
        }
        else {
           System.out.println("Не високосный год ");
        }
            //days[1] = 29; // Високосный
          //return 0;
        }
//}    return year;
          return 0;
    }      

}  
//}



public class NewCalendarTest {
    public static void main(String[] args) {
        NewCalendar nc = new NewCalendar();
nc.setYear(2021);
        System.out.println(" " + nc.year());
    }
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Zagaevsky, 2021-05-13
@Sergei1111

Because year() returns 0(return 0;). You need to use getYear()

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question