1
我試圖做的代碼輸入出生日期,讓那一天的一週的迴天,我使用的輸入流閱讀讓我輸入使用int值作爲GregorianCalendar的輸入,但我不能夠繼續掃描JAVA
package testing;
import java.io.*;
import java.text.DateFormat;
import java.util.*;
public class theDayYouBorn {
public static void main(String[] args) throws IOException {
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader br = new BufferedReader(isr);
System.out.println("Please Input the Year You Born at : ");
int year1 = br.read();
System.out.println("Thank!, Please input the Month :");
int month1 = br.read();
System.out.println("Okay, last thing Please input the day : ");
int day1 = br.read();
GregorianCalendar gc = new GregorianCalendar(year1, month1, day1);
Date d1 = gc.getTime();
DateFormat df = DateFormat.getDateInstance();
String sd = df.format(d1);
String dayName = gc.getDisplayName(gc.DAY_OF_WEEK, gc.LONG,
Locale.getDefault());
System.out.println("The Day you born in was a " + sd
+ " and the day was " + dayName);
}
}
它讓我把第一輸入,然後它的運行和隨機日期不要求一天或一個月
然後我嘗試使用字符串作爲輸入,並將其轉換成整數,它的工作......我改變了:
System.out.println("Please Input the Year You Born at : ");
String year = br.readLine();
System.out.println("Thank!, Please input the Month :");
String preMonth = br.readLine();
System.out.println("Okay, last thing Please input the day : ");
String day = br.readLine();
int day1 = Integer.parseInt(day);
int month2 = Integer.parseInt(preMonth);
int year1 = Integer.parseInt(year);
int month1 = month2 - 1;
我試圖理解爲什麼我不能夠掃描整數。
請閱讀本:(https://docs.oracle.com/javase/7/docs/api/java/io/BufferedReader.html#read%28%29)的'讀()'的JavaDoc]: *讀取單個字符。* – Tom