我在尝试使用时遇到错误Integer.parseInt()
。它们是,没有找到适合 parseInt(int) 的方法,而 Integer.pasreInt(String) 方法不适用。
import java.io.InputStream;
import java.util.Scanner;
import java.util.regex.Pattern;
class bday1
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
int day;
int month=0;
int year;
int whatDay;
int howManyDays=0;
int leapYear;
final int JANYEAR = 1901;
int[] dayMonth = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
boolean numberEntered=true;
String strMonth;
String[] days = {"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"};
System.out.print("What is your birthdate? ");
sc.useDelimiter(Pattern.compile("[-/.\\s]"));
day = sc.nextInt();
strMonth = sc.next();
year = sc.nextInt();
if((strMonth.charAt(0) >='0') && (strMonth.charAt(0) <='9'))
{
numberEntered=true;
System.out.println ("number entered");
}
if(numberEntered)
{
strMonth=Integer.parseInt(month);
}
else
{
System.out.println ("string entered");
}
那是我的代码片段,我相信我遇到了麻烦。任何帮助都会很棒。