Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/383.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何使用“DOB”获取年龄;“本地日期”;而不是写在;“本年度”;使用-用户输入-?_Java - Fatal编程技术网

Java 如何使用“DOB”获取年龄;“本地日期”;而不是写在;“本年度”;使用-用户输入-?

Java 如何使用“DOB”获取年龄;“本地日期”;而不是写在;“本年度”;使用-用户输入-?,java,Java,如何更改此代码,使其从本地日期获取年龄,而不是使用“当前年份是什么” 这就是我到目前为止所做的: //---------------------------------------------------------------- public static void main(String args[]) { Scanner input = new Scanner(System.in); try { System.out.println("Please enter

如何更改此代码,使其从本地日期获取年龄,而不是使用“当前年份是什么”

这就是我到目前为止所做的:

//----------------------------------------------------------------

public static void main(String args[]) {
  Scanner input = new Scanner(System.in);

  try {
         System.out.println("Please enter your name: ");
            String name = input.nextLine();

         System.out.println("Please enter your birth date: ");
            String date = input.nextLine();

         System.out.println("please enter your birth month:");
            String month = input.nextLine();

         System.out.println("please enter your birth year:");
            String year = input.nextLine();

         System.out.println("please enter current year:");
            String cYear = input.nextLine();


             int bDate = Integer.parseInt(date);
             int bMonth = Integer.parseInt(month);
             int bYear = Integer.parseInt(year);
             int ccYear = Integer.parseInt(cYear);

          int age = ccYear - bYear;
          int totalMonth = 12;
          int yourMonth = totalMonth - bMonth;

    System.out.println(" Hi " + name + " your are " + age + " years  ");
  } catch(Exception e) {
    System.out.println("");
  }
}

可以使用标准的
Calendar
API获取当前年份

int year = Calendar.getInstance().get(Calendar.YEAR);

从这里开始,您只需将其插入代码中正确的位置。

此问题的哪一部分需要帮助?用户本地日期是什么意思?