package age;
import java.util.Scanner;
public class AgeTest
{
public static void main(String[] args)
{
Scanner input = new Scanner(System.in);
Age myAge = new Age();
System.out.printf("initial age is :%s%n%n"+ myAge.getAge());
System.out.println("PLEASE ENTER THE AGE");
int theAge = input.nextInt();
myAge.setAge(theAge);
System.out.println();
// display the name stored in object myAge
System.out.printf("age in object myAge is %n%s%n"+ myAge.getAge());
有什么问题?
答案 0 :(得分:0)
我猜你的getAge()方法返回一个int。因此,尝试将myAge.getAge()解析为String,如:
String age = Integer.toString(myAge.getAge())
System.out.print("Age is: " + age );