为什么是输出?:球体 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和c中打印出迭代器(i)1.000.000次.
我分别使用netbeans和visual studio.
我不关心精度,但大约40秒:
netbeans(java)打印了大约500.000个数字,而windows(c)打印了大约75.000个数字
- 为什么这么大的差异?
我使用通用的intel core2duo(2.0 Ghz)pc与windows7
我是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()功能吗?
我想知道通过在Firefox中使用JavaScript来使用打印选项。
我的页面上有打印链接:
<a href="javascript:print()">print</a>
Run Code Online (Sandbox Code Playgroud)
我还按照关于Javascript的打印按钮页面上的说明进行操作。
问题是当我尝试在Firefox下打印页面时,我得到了一个四页的PDF预览,其中缺少内容:
我尝试使用Chrome,并且可以正常使用。
有任何想法吗?
我正在用Java制作一个地下城游戏.我创建了一个将地图存储在2D数组中的方法.该数组如下所示:
[[#, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #, #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., ., ., ., ., G, ., ., ., ., ., ., ., ., E, ., #],
[#, ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., ., #],
[#, ., ., …Run Code Online (Sandbox Code Playgroud) java printing arrays multidimensional-array indexoutofboundsexception
当我遇到以下情况时,我正在解决问题的解决方案......
我开始创建一个变量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,我只是好奇为什么这是.
我已经覆盖了类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 …
我的程序在网格中绘制框.这是完整的代码: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) 当我在代码下面运行时,我得到"语法错误:语法无效".但是,如果我在打印后用括号运行此代码,我会得到正确的答案.
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) 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) printing ×10
java ×4
python ×3
arrays ×1
c ×1
common-lisp ×1
comparison ×1
firefox ×1
implicit ×1
integer ×1
javascript ×1
lisp ×1
nonetype ×1
performance ×1
perl ×1
python-2.7 ×1
recursion ×1
string ×1
syntax-error ×1
tostring ×1
tree ×1
variables ×1