// strings/Turtle.java// (c)2017 MindView LLC: see Copyright.txt// We make no guarantees that this code is fit for any purpose.// Visit http://OnJava8.com for more book information.import java.io.*;import java.util.*;public class Turtle {private String name;private Formatter f;public Turtle(String name, Formatter f) {this.name = name;this.f = f;}public void move(int x, int y) {f.format("%s The Turtle is at (%d,%d)%n",name, x, y);}public static void main(String[] args) {PrintStream outAlias = System.out;Turtle tommy = new Turtle("Tommy",new Formatter(System.out));Turtle terry = new Turtle("Terry",new Formatter(outAlias));tommy.move(0,0);terry.move(4,8);tommy.move(3,4);terry.move(2,5);tommy.move(3,3);terry.move(3,3);}}/* Output:Tommy The Turtle is at (0,0)Terry The Turtle is at (4,8)Tommy The Turtle is at (3,4)Terry The Turtle is at (2,5)Tommy The Turtle is at (3,3)Terry The Turtle is at (3,3)*/
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。