0

I'm trying to get an input(year) from the user and if the user enters four digit input(which is the length) then it will print the year, but if the user enters any other length it will ask again. Why I can't do(year.length ==4); doesn't it means that if the year length is 4 then finish the loop? Thanks

import java.util.Scanner;

public class years {
  public static void main(String[] args) {
    int year;
    Scanner input = new Scanner(System.in);
    do {
      year = input.nextInt();
    }while(year.length == 4);

    System.out.println("Year is " + year);
  }
}

0 Answers0