Java 打印对账单时给出;找不到符号“;消息
我在玩java时遇到了以下问题 我有以下课程Java 打印对账单时给出;找不到符号“;消息,java,netbeans,Java,Netbeans,我在玩java时遇到了以下问题 我有以下课程 class Training{ public static void main(String[]args){ book firstBook = new book("Hamlet","William Shakespeare"); book secondBook = new book("Heart of Darkness", "Joseph Conrad"); book thirdBook = new
class Training{
public static void main(String[]args){
book firstBook = new book("Hamlet","William Shakespeare");
book secondBook = new book("Heart of Darkness", "Joseph Conrad");
book thirdBook = new book("Database Design","M Hernandez");
System.out.println();
System.out.println("Total number of books is " + book.noOfBooks + "\n");
System.out.println();
}
}
public class book {
private String name;
private String author;
private int id;
public static int noOfBooks = 0;
public book(String n, String a){
name = n;
author = a;
id = ++noOfBooks;
System.out.printf("The book you've just created is %s\n", this);
}
public String toString(){
return String.format("%s by %s id %d", name, author, id);
}
public String getName(){
return name;
}
public String getAuthor(){
return author;
}
public int getID(){
return id;
}
}
public class whatDay {
System.out.println();
}
NetBeans在whatDay
类中为print语句抛出消息“找不到符号”
知道问题可能是什么吗?由于whatDay类中对println的调用未包含在方法中,因此出现了错误。问题是
系统.out.println()因为您没有将其放入方法中
尝试将System.out.println()放入一个方法中。
例如:
public class WhatDay {
// Constructor
public WhatDay() {
System.out.println()
}
}
顺便说一句:你应该以大写字母开始类名
玩得开心:)@zan,如果这个答案适合你,请。