Saya sedang menulis program untuk sekolah. Saya telah menyelesaikan sebagian besarnya tetapi saya terus mendapatkan kesalahan tipe tak terduga: nilai yang diperlukan kelas ditemukan tepat setelah objek pemindai saya. Kelihatannya benar bagi saya tetapi saya terus mendapatkan kesalahan ini. Bantuan apa pun akan dihargai.
/**
*
* @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
Secara khusus, itu ada pada kode ini.
int tahun_kelahiran = int tahun.nextInt();
Terima kasih
int
kedua dari baris itu. - person shmosel   schedule 04.07.2014static
tersebut mungkin tidak bolehstatic
, dan Anda sebenarnya tidak perlu menandai kurung kurawal seperti itu -- lekukan yang baik sudah cukup untuk Anda. - person awksp   schedule 04.07.2014