这是代码:
class Time {
public static void printTime (int hour, int minute) {
System.out.print (hour) ;
System.out.print (":") ;
System.out.print (minute) ;
}
public static void main (String[] args) {
hour = 11 ;
minute = 30 ;
printTime () ;
}
}
Run Code Online (Sandbox Code Playgroud)
当我尝试编译时,这是终端所说的:
david-allenders-macbook-pro:~ davidallender$ Javac Time.java
Time.java:9: cannot find symbol
symbol : variable hour
location: class Time
hour = 11 ;
^
Time.java:10: cannot find symbol
symbol : variable minute
location: class Time
minute = 30 ;
^ …Run Code Online (Sandbox Code Playgroud) 在调整向Java返回true/false的C风格函数时,最佳做法是什么?
这是一个简单的方法来说明问题所在.
public static boolean fileNameEndsWithExtension( String filename, String fileExtension) {
return filename.endsWith( fileExtension );
}
Run Code Online (Sandbox Code Playgroud)
请注意,可能有一种更优雅的过滤文件的方式(随意评论).无论如何,如果filename是一个null值,那么做一个:
null的情况String和文件名不以给定文件扩展名结尾的情况?null值的包装器类Boolean .Exception并强制程序员确保一个null值永远不会传递给方法?有人在我之前处理我的代码,创建了一些方法并将Runnable作为参数传递,更有可能:
void myMethod(Runnable runnable){ runnable.run(); }
Run Code Online (Sandbox Code Playgroud)
然后从主要调用myMethod看起来像:
public static void main(String args[])
{ try
{ myMethod(new Runnable(){ public void run() { //do something...; }}); }
catch (Throwable t) { } }
Run Code Online (Sandbox Code Playgroud)
因此,要向myMethod提供参数,我需要实例化实现Runnable的(在这种情况下是匿名)类的对象.
我的问题是:在这个例子中是否有必要使用Runnable?我可以使用任何不同的界面吗?我的意思是我可以使用单一方法创建新界面,即
interface MyInterface{ void doThis(); }
Run Code Online (Sandbox Code Playgroud)
然后改变myMethod的外观: void myMethod(MyInterface myObject){ myObject.doThis(); }
客户当然也是:
public static void main(String args[]) {
try { myMethod(new MyInterface (){ public void doThis()
{ //do something...; }}); }
catch (Throwable t) { } }
Run Code Online (Sandbox Code Playgroud)
或者也许是关于Runnable的东西?!
我正在尝试使用Hoard分配器来工作,但它似乎没有.我有一个基准测试应用程序,可以进行大量的动态内存管理.Hoard和glibc内存管理器的执行时间是一样的.这让我想知道我是不是做对了.
我做的是......
export LD_PRELOAD="/path/libhoard.so"
g++ main.cpp -O3 -o bm -lpthread -lrt
Run Code Online (Sandbox Code Playgroud)
我不应该链接到Hoard分配器吗?路径(在LD_PRELOAD中)是否重要,或者我可以拥有任何路径?
我正在运行Ubuntu 8.04和g ++ 4.2.4
干杯
没有人知道任何Linux命令(如grep)来确定Hoard是否正确加载,并且是否使用了实际的分配器?
在safari 4和所有资源管理器浏览器中,每当我尝试在下面包含此函数的javascript文件中调用函数时,都不会调用第一个函数.
因此,如果function2在同一个.js文件中,调用function1将不起作用,解释?
这是产生问题的代码.每当我删除此功能,一切正常,所有功能都可以正常工作.所以这个功能导致了一个问题.
function addOption(selectbox, value, text, class, id_nr )
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
optn.id = value;
if (class==1){ optn.className = "nav_option_main"; }
selectbox.options.add(optn);
}
Run Code Online (Sandbox Code Playgroud)
有什么想法吗?
谢谢
我正在使用C#学习设计模式.我面临的挑战之一是它们看起来很相似.你能帮我区分一下 - 基本上什么时候使用它们? - 为什么不是另一个?
我知道网络上有很多可用的资源.但是他们没有对待这种特殊情况.
[注意:我正在寻找选择背后的实施例子和理由; 不仅仅是解释]
感谢您的答复.我更多地尝试学习Bridge.
我有以下场景.
在我的房间里有两台电视.每个人都有自己的遥控器; 但两者都有相同的界面供用户使用.但是我想拥有自己的遥控器,我将使用两个遥控器中的任何一个的处理器.
我有以下代码.我想,这是战略模式.我想把它转换成Bridge.
转换成Bridge后我会得到什么好处?
公共课PhilliTV {public void Begin(){Console.WriteLine("PhilliTV Bagan"); }}
public class SonTV
{
public void Initiate()
{
Console.WriteLine("SonTV Initiated");
}
}
public class SonRemote : IRemote
{
SonTV stv = new SonTV();
public void Play()
{
stv.Initiate();
}
}
public class PhilliRemote : IRemote
{
PhilliTV ptv = new PhilliTV();
public void Play()
{
ptv.Begin();
}
}
public class URemoteConsumer
{
IRemote remote = …Run Code Online (Sandbox Code Playgroud)我的PHP代码中有一个使用递归的问题:
<?php
solveTowers(5, "A", "B", "C");
function solveTowers($count, $src, $dest, $spare)
{
if (count == 1)
{
echo "Move a disk from ".$src." to ".$dest ;
}
else
{
solveTowers($count - 1, $src, $spare, $dest);
solveTowers(1, $src, $dest, $spare);
solveTowers($count - 1, $spare, $dest, $src);
}
}
?>
Run Code Online (Sandbox Code Playgroud)
但它没有运行!
发生此错误:
致命错误:第13行的C:\ xampp\htdocs\cap492\towers.php中允许的内存大小为134217728字节(试图分配261904字节)
第13行是else语句中对函数的第一次调用
你能帮我解决这个问题吗?!
我在C#中的代码有问题.如果我单击编译器按钮,我会收到以下错误
'
System.Collections.Generic.LinkedList<int?>'不包含'removeFirst'的定义,并且没有扩展方法'removeFirst'接受类型'System.Collections.Generic.LinkedList<int?>' 的第一个参数可以找到(你是否缺少using指令或汇编引用?).
和
'
System.Collections.Generic.LinkedList<Hanoi_tower.Sol>'不包含'addLast'的定义,并且没有扩展方法'addLast'接受类型'System.Collections.Generic.LinkedList<Hanoi_tower.Sol>' 的第一个参数可以找到(你是否缺少using指令或汇编引用?)
这是我的计划
using System.;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Hanoi_tower
{
public class Sol
{
public LinkedList<int?> tower1 = new LinkedList<int?>();
public LinkedList<int?> tower2 =new LinkedList<int?>();
public LinkedList<int?> tower3 =new LinkedList<int?>();
public int depth;
public LinkedList<Sol> neighbors;
public Sol(LinkedList<int?> tower1, LinkedList<int?> tower2, LinkedList<int?> tower3)
{
this.tower1 = tower1;
this.tower2 = tower2;
this.tower3 = tower3;
neighbors = new LinkedList<Sol>();
}
public virtual void getneighbors()
{
Sol …Run Code Online (Sandbox Code Playgroud) java ×4
c# ×2
boolean ×1
c++ ×1
hoard ×1
html ×1
interface ×1
javascript ×1
methods ×1
parameters ×1
php ×1
recursion ×1
text-files ×1