【发布时间】:2013-10-27 23:14:54
【问题描述】:
我正在尝试在一行代码中打印出整个“f”变量。f 显然代表女性,但是当我使用我的代码方式时它显示错误?
对不起,我是初学者。
import java.util.*;
class university {
public static void main(String[] args){
Scanner scanner = new Scanner(System.in);
Person2 mPerson, fPerson = null;`
String fFirstName, fSurname, mFirstName, mSurname;
int fAge, mAge;
System.out.println("Please enter the firstname of your favourite female author");
fFirstName = scanner.nextLine();
System.out.println("Please enter her second name");
fSurname = scanner.nextLine();
System.out.println("Please enter her age");
fAge = scanner.nextInt();
scanner.nextLine();
System.out.println("Please enter the firstname of your favourite female author");
mFirstName = scanner.nextLine();
System.out.println("Please enter her second name");
mSurname = scanner.nextLine();
System.out.println("Please enter her age");
mAge = scanner.nextInt();
fPerson = new Person2(fFirstName, fSurname, fAge);
System.out.print(fPerson);
}
}
【问题讨论】:
-
什么错误?
fPerson2是如何定义的? -
没有“fperson2”
-
1) 为了尽快获得更好的帮助,请发帖 SSCCE。 2) 始终复制/粘贴错误和异常输出。
-
天啊,对不起。
person2是如何定义的?如果你不花时间格式化你的代码,事情就会被误读。 -
我搜索了"how to print a class in Java",你猜怎么着?
标签: java