标签: printing

为什么这段 Java 代码隐式调用 toString() 方法?

为什么是输出?:球体 0

它以某种方式隐式调用 toString() 方法?这是如何运作的 ?

class BerylliumSphere {
    private static long counter = 0;
    private final long id = counter++;
    public String toString() { 
        return "Sphere " + id;
    }
}

public class Test {
    public static void main (String[] args) {
        BerylliumSphere spheres = new BerylliumSphere();
        System.out.println(spheres);
    }
}

// output: Sphere 0 
Run Code Online (Sandbox Code Playgroud)

java printing tostring implicit

-1
推荐指数
1
解决办法
1077
查看次数

Java与C简单性能测试

即运行一个简单的循环,在java和c中打印出迭代器(i)1.000.000次.

我分别使用netbeans和visual studio.

我不关心精度,但大约40秒:

netbeans(java)打印了大约500.000个数字,而windows(c)打印了大约75.000个数字

- 为什么这么大的差异?

我使用通用的intel core2duo(2.0 Ghz)pc与windows7

c java printing comparison performance

-2
推荐指数
1
解决办法
819
查看次数

Perl - myprint()或重载打印命令的新定义

我是Perl的新手.我正在编写一些脚本,并希望定义我自己的打印调用myprint(),它将根据一些标志打印传递给它的东西(详细/调试标志)

open(FD, "> /tmp/abc.txt") or die "Cannot create abc.txt file";
print FD "---Production Data---\n";
myprint "Hello - This is only a comment - debug data";
Run Code Online (Sandbox Code Playgroud)

有人可以帮我提供一些示例代码来实现myprint()功能吗?

printing perl

-2
推荐指数
1
解决办法
349
查看次数

通过`print()`打印不会在Firefox中打印所有页面

我想知道通过在Firefox中使用JavaScript来使用打印选项。

我的页面上有打印链接:

<a href="javascript:print()">print</a>
Run Code Online (Sandbox Code Playgroud)

我还按照关于Javascript的打印按钮页面上的说明进行操作。

问题是当我尝试在Firefox下打印页面时,我得到了一个四页的PDF预览,其中缺少内容:

  • 第一页为空,
  • 第二个将从应该在第三页上的内容开始,然后
  • 第三和第四页为空

我尝试使用Chrome,并且可以正常使用。

有任何想法吗?

javascript printing firefox

-2
推荐指数
1
解决办法
770
查看次数

ArrayIndexOutOfBoundsException,仅打印第一行

我正在用Java制作一个地下城游戏.我创建了一个将地图存储在2D数组中的方法.该数组如下所示:

[[#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., ., ., ., ., G, ., ., ., ., ., ., ., ., E, ., #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., …
Run Code Online (Sandbox Code Playgroud)

java printing arrays multidimensional-array indexoutofboundsexception

-2
推荐指数
2
解决办法
95
查看次数

Python print返回None

当我遇到以下情况时,我正在解决问题的解决方案......

我开始创建一个变量test,并将其初始化为一个列表.

test = [3, 2, 1]
Run Code Online (Sandbox Code Playgroud)

.sort()我的名单上玩并调用它后test,我尝试使用print如下:

print test.sort(reverse = True)
Run Code Online (Sandbox Code Playgroud)

输出是None,我只是好奇为什么这是.

python printing

-2
推荐指数
1
解决办法
82
查看次数

我不能做System.out.println(Item.toString());?

我已经覆盖了类Object的toString方法,但我的方法不起作用,我无法弄清楚原因.这是我的方法的代码(在一个名为的类中ShoppingBag):

public String toString(){ 
    String str = ""; 
    Item temp = record;  
    str += "\n\nThe bag contains:\n"; 
    str += String.format("%-18s%-13s%-12s\n", "Name of the Items", "Quantity", "Subtotal"); 
    while(temp != null){ 
        str += String.format("%-18s%-13s%-12s\n", temp.getItemName(), temp.getQuantity(),
           "$"+(temp.getRetailPrice()*temp.getQuantity()));
    }
    str += String.format("%-18s%-13s%-12s\n", "", "Total:", "$"+this.totalCost()); 
    str += String.format("%-18s%-13s%-12s\n", "", "Tax(5%):", "$"+(this.totalCost()
          * taxRate)); 
    str += String.format("%-18s%-13s%-12s\n", "", "Grand Total:", "$"+this.totalCost()
          +(this.totalCost()*taxRate)); 
    String test = "test1";
    return test;
}
Run Code Online (Sandbox Code Playgroud)

我知道那里有很多带有Item和String.format的垃圾.编译或运行时没有例外,它只是不打印任何东西.

在我的应用程序中,我试试这个:

ShoppingBag bag = new ShoppingBag(parameters);
System.out.println(bag.toString());
Run Code Online (Sandbox Code Playgroud)

并没有打印.当我注释掉除了我的方法(String test …

java printing string

-2
推荐指数
1
解决办法
88
查看次数

Python打印没有在控制台没有明显的原因?

我的程序在网格中绘制框.这是完整的代码:http://pastebin.com/cMEJAAES

这里的想法是我需要一个调试方法.它应该打印乌龟刚绘制的盒子的坐标,它的颜色.由于某种原因,它打印很好,但中间有一个随机的无.这是一些控制台输出的示例:

Reading map data....
Drew tile 1 (1,1)
None as color 3
Drew tile 2 (1,2)
None as color 0
Run Code Online (Sandbox Code Playgroud)

这是我的代码:

#Define our map to draw.
map = [3,           #Set row width.
        3, 0, 0,    #Row data.
        0, 2, 1,
        2, 1, 1]
Run Code Online (Sandbox Code Playgroud)

[...]

def drawmap(m):
#Print the entire map.
    for x in range (0, len(m)):
        if x == 0:
            print("Reading map data....") #Not really, just skipping index 0.
        else:
            draw_tile(map[x])
            lastbox = x
            tileinfo(x)
            move(m, …
Run Code Online (Sandbox Code Playgroud)

python printing variables integer nonetype

-2
推荐指数
1
解决办法
268
查看次数

打印不在没有括号的情况下工作(Python 2.7)

当我在代码下面运行时,我得到"语法错误:语法无效".但是,如果我在打印后用括号运行此代码,我会得到正确的答案.

liczby = [
951, 402, 984, 651, 360, 69, 408, 319, 601, 485, 980, 507, 725, 547, 544,
615, 83, 165, 141, 501, 263, 617, 865, 575, 219, 390, 984, 592, 236, 105, 942, 941,
386, 462, 47, 418, 907, 344, 236, 375, 823, 566, 597, 978, 328, 615, 953, 345,
399, 162, 758, 219, 918, 237, 412, 566, 826, 248, 866, 950, 626, 949, 687, 217,
815, 67, 104, 58, 512, 24, 892, 894, 767, 553, 81, 379, …
Run Code Online (Sandbox Code Playgroud)

python printing compiler-errors syntax-error python-2.7

-2
推荐指数
1
解决办法
2068
查看次数

如何在没有dolist的情况下在lisp中打印树,只有递归?

INPUT :( A(B(D(E)(F)))(C)(K))我目前有两个函数,它给我一个OUTPUT:

一个

C

ķ

d

d

Ë

F

Ë

但是我需要这样的输出:
a:bck
b:d
c:
k:
d:ef

E:

F:

要么

一个

BSK

d

EF

(defun print-children (s)
   (cond ((null (caar (cdr s))) nil) 
         (t (print (caar (cdr s))) (print-children (cdr s)))))

(defun print-tree (s)
  (cond ((null s) nil)
        ((atom (car s)) (print (car s)) (print-children s) (print-tree (cdr s)))
        (t (print-tree (car s)))))
Run Code Online (Sandbox Code Playgroud)

lisp printing tree recursion common-lisp

-2
推荐指数
1
解决办法
296
查看次数