I am trying to parse out a mm/dd/yyyy
formatted date into separate fields, but I get the following error when I try to compile:
non-static method next() cannot be referenced from a static context
What could be causing the error?
import java.util.Scanner;
public class Problem39
{
public static void main(String [ ] args)
{
boolean isLeapYear =false;
int maxDay=0;
String stringDate;
System.out.println("Enter the date in mm/dd/yyyy format. "); //user input
Scanner keyboard = new Scanner(System.in); //read input
String date=Scanner.next(); //store input
String temp=date.split("/"); //parse date
int month=IntegerParseInt(temp[1]);
int day=IntegerParseInt(temp[0]);
int year=IntegerParseInt(temp[2]);
它应该是keyboard.next()
而不是Scanner.next()
。
You mean
String date = keyboard.next();
instead of
String date = Scanner.next();
Change the code:
String date=Scanner.next();
to:
String date = keyboard.next();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.