ฉันกำลังเขียนโปรแกรมสำหรับโรงเรียน ฉันดำเนินการส่วนใหญ่เสร็จแล้ว แต่ยังคงได้รับข้อผิดพลาดประเภทที่ไม่คาดคิด: required value found class ทันทีหลังจากวัตถุสแกนเนอร์ของฉัน มันดูถูกต้องสำหรับฉัน แต่ฉันได้รับข้อผิดพลาดนี้ต่อไป ความช่วยเหลือใด ๆ ที่จะได้รับการชื่นชม
/**
*
* @author Randy
*/
import java.util.Scanner;//Import scanner
public class RandyGilmanhw2a {
static int year_of_birth;
static int age;
public RandyGilmanhw2a (){//begin constructor
year_of_birth = 1900;
age = 0;
}//end constructor
public int getYear(){//get year method
return year_of_birth;
}//end method
public int getAge(int year_of_birth){//get year method
age = 2014 - year_of_birth;
return age;
}//end get year method
public void setYear (int year){//set year method
this.year_of_birth = year;
}//end method
public static void main(String[] args) {//begin main
RandyGilmanhw2a user1 = new RandyGilmanhw2a();
Scanner year = new Scanner(System.in);//create a scanner object
System.out.println("Please enter the year you were born: ");
int year_of_birth = int year.nextInt();
while( year_of_birth < 1900 || year_of_birth > 2014 ) {//begin while loop
System.out.print("Please reenter the year you were born." );
System.out.print("You must have an integer between 1900 and 2014:" );
System.out.print("\n");
}//end while
user1.getAge(year_of_birth);
System.out.print("You are " + age + "years old." );
}//end main
}//end class
โดยเฉพาะอยู่ที่รหัสนี้
int year_of_birth = int year.nextInt();
ขอบคุณ
int
ตัวที่สองออกจากบรรทัดนั้น - person shmosel   schedule 04.07.2014static
เหล่านั้นอาจไม่ควรเป็นstatic
และคุณไม่จำเป็นต้องทำเครื่องหมายวงเล็บปีกกาแบบนั้น การเยื้องที่ดีควรทำเพื่อคุณ - person awksp   schedule 04.07.2014