- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
到目前为止,我已经完成了一个项目,这是我想要的输出:
测试 1
和
测试 2
以下是说明。“编写一个名为 Book 的类,其中包含标题、作者和页面的实例数据。定义 Book 构造函数以接受并初始化此数据。包括所有实例数据的 setter 和 getter 方法。包括toString 方法返回如下字符串:
Author: name of the author in one word
Title: title in one word
Pages: number of pages
示例:
Author: Lewis
Title: Java
Pages: 806
编写一个 BookTester 类,从键盘获取作者、标题、页面,创建一个书籍对象并将以上内容打印到屏幕上。我如何得到我的答案来显示我的图片测试 1 和测试 2 中显示的预期输出?另外,我错过了什么?
预订
public class Book {
String author;
String title;
int pages;
public Book(String a, String t, int p) {
author = a;
title = t;
pages = p;
}
public String toString() {
String output;
output = ("Author: " + author + "\n");
output = ("Title: " + title + "\n");
output = ("Pages: " + pages + "\n");
return output;
}
}
图书测试仪
import java.util.*;
public class BookTester {
public static void main(String[] args) {
String author;
String title;
int pages;
Scanner scan = new Scanner(System.in);
author = scan.nextLine();
title = scan.nextLine();
pages = scan.nextInt();
Book book1 = new Book(author, title, pages);
System.out.println(book1);
}
}
最佳答案
@Override
public String toString() {
String output ="";
output += "Author: " + author + "\n";
output += "Title: " + title + "\n";
output += "Pages: " + pages + "\n";
return output;
}
您应该连接 (+) 每个值。否则将返回最后一个值(意味着Pages: ---
)。
关于java - 写作课我错过了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35377557/
我正在尝试使用 http://fsprojects.github.io/ExcelProvider/ 中的 ExcelProvider .我不确定我是否遗漏了什么,但有什么方法可以实际编写 Excel
我正在用 C 编写程序,我想我在内存方面遇到了一些麻烦。 所以我的问题是:我有 2 个返回结构的函数。当我一次只运行一个函数时,我没有任何问题。但是当我一个接一个地运行时,我在写入第二个结构时总是会出
我正在使用以下代码通过 scrapey 抓取数据: from scrapy.selector import Selector from scrapy.spider import Spider clas
我偶然发现了文件处理问题, 第二行无缘无故为您提供9的值, 第三行给出错误io.UnsupportedOperation:不可读 c = open("Test.txt", "w+") c.write(
我正在向 CSV 文件写入一个函数(正在运行),但是它在最后一行中被中途切断。我知道这可能与文件的关闭有关,但我认为我做得正确。 有什么可能出错的地方吗? from itertools import
作为新用户,我设法制作了一个蜘蛛可以爬行的电子商务网站并提取每个产品的标题和变体以及输出的 CSV 文件和产品线,但我希望的是这是逐行的变化,请有人帮助我推进我的项目。 我很期待这个问题,但不幸的是我
我只是一个在业余时间编写 iOS 和 Andorid 应用程序的人。我有一些 Android 应用程序,我认为它们很适合进行更新,使它们能够在 Honeycomb 上本地运行。 但是,由于我没有 Ho
嘿,所以我并没有真正弄乱它太多,但我想知道是否真的有一种方法(在我陷入无休止的兔子洞之前)在 Dart/Flutter 中读取和写入 CSV 文件?我需要写入文件,不一定要读取它们,而且我愿意为此付出
当谈到 OCaml 时,我是一个完整的新手。我最近才开始使用该语言(大约 2 周前),但不幸的是,我的任务是为一种组合语言制作一个语法分析器(解析器 + 词法分析器,其功能是接受或不接受句子)使用门希
你能给我一些很好的引用资料吗,我可以如何通过 .net 资源读写注册表? 我查看了网站,找不到任何有用的信息。 最佳答案 检查 BCL 中的 Registry 类 http://msdn.micros
我正在开发一个可以生成大量数据并将其存储到磁盘的系统。该公司之前开发的一个系统使用普通文件来存储其数据,但由于多种原因,它变得非常难以管理。 我相信 NoSQL 数据库对我们来说是很好的解决方案。我们
如主题标题。当我写:void fun(int *tab){} 和写 void fun(int tab[]){} 一样吗? 最佳答案 是的。 void fun(int *tab){} void fun(
想不通此函数(用于将互联网站点抓取为 pdf 的类的一部分)应该合并使用 pypdf 从网页生成的 pdf 文件。 这是方法代码: def mergePdf(self,mainname,inputli
我是一名优秀的程序员,十分优秀!