我有以下代码来自Sun认证Java程序员的模拟考试:
public class Static
{
static
{
int x = 5;
}
static int x,y;
public static void main(String args[])
{
x--; myMethod();
System.out.println(x + y + ++x);
}
public static void myMethod()
{
y = x++ + ++x;
}
}
Run Code Online (Sandbox Code Playgroud)
测试会询问您此行的结果:
System.out.println(x + y + ++x);
Run Code Online (Sandbox Code Playgroud)
答案是3,但我不完全理解为什么它是3.如果我完全忽略,我可以得到答案:
static
{
int x = 5;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,上面代码片段的含义是什么?为什么它不改变变量'x'的值?
我试图嵌套多个if语句如下:
#!/bin/bash
# start_server.sh
#
# Use this script to start the MarketDataTransmitter.
#
# Usage: ./start_server.sh Starts the MarketDataTransmitter.
reset=$(tput sgr0)
red=$(tput setaf 1)
green=$(tput setaf 2)
yellow=$(tput setaf 3)
cyan=$(tput setaf 6)
echo
directory=$(ls -l)
check_exist=$(awk -v a="$directory" -v b="MarketDataTransmitter" 'BEGIN { print index(a, b) }')
if [ "$check_exist" = "0" ]; then
# MarketDataTransmitter is not present.
echo "${red}[ERROR]${reset} Could not start ${yellow}MarketDataTransmitter${reset}."
echo " ${yellow}MarketDataTransmitter${reset} could not be found."
else
# MarketDataTransmitter is present.
processes=$(ps -ef …Run Code Online (Sandbox Code Playgroud) 以下代码段将导致运行时:
class Vehicle {
public void printSound() {
System.out.print("vehicle");
}
}
class Car extends Vehicle {
public void printSound() {
System.out.print("car");
}
}
class Bike extends Vehicle {
public void printSound() {
System.out.print("bike");
}
}
public class Test {
public static void main(String[] args) {
Vehicle v = new Car();
Bike b = (Bike) v;
v.printSound();
b.printSound();
}
}
Run Code Online (Sandbox Code Playgroud)
我的问题是:为什么会导致运行时错误而不是编译错误?难道编译器不应该知道'v'已经是'Car'并且不能被投入'Bike'吗?
我的 Excel 文档默认 allTrue和Falsestrings 为TRUEand FALSE,然后将其视为布尔值,这在我的宏中失败。
我可以right click -> format cells -> select text,但我不知道用户将使用哪些单元格,因此此方法不起作用。
是否有禁用此自动转换的全局方法或使用 VBA 的方法?
下 /usr/share/lib/zoneinfo
我可以看到以下4种不同类型的信息 GMT
GMT
GMT+0
GMT-0
GMT0
Run Code Online (Sandbox Code Playgroud)
这四种GMT区域时间之间是否有任何差异?如果是这样,有什么区别?
我需要一些帮助来找到一种方法来检查目录中是否存在与特定正则表达式匹配的文件。目前,我使用以下方法,但在某些情况下会返回错误:
ls srv_*.log
Run Code Online (Sandbox Code Playgroud)
如果目录中没有与正则表达式匹配的文件,上述命令将导致ls:cannotaccesssrv_*.log: Nosuchfileordirectory。
我试图匹配的正则表达式是“srv_*.log”
有人有什么想法吗?
谢谢。
我正在尝试使用boost::is_any_of和编写一段简单的代码boost::replace_all_copy.该片段如下:
std::string someString = "abc.def-ghi";
std::string toReplace = ".-";
std::string processedString = boost::replace_all_copy(someString, boost::is_any_of(toReplace), " ");
Run Code Online (Sandbox Code Playgroud)
但是,我得到的编译器错误太长,无法在此处粘贴.有经验这两个功能的人可以指出我的错误吗?
我在shell脚本的循环中运行Perl脚本:
while [ $currentDate -le $toDate ]; do
// code here...
exec /users/my_user/script_name $currentDate
// code here...
done
Run Code Online (Sandbox Code Playgroud)
我已经确认了while-loop循环.但是,在运行一次Perl脚本之后,while-loop结束了.
有人可以对此有所了解吗?
我知道用于Java中文件目录处理的Apache Commons IO库.但是,使用Java递归列出目录中的所有文件,讨论Java 7中的本机支持.
有没有人有过如何使用Java 7递归列出/读取目录中的文件的经验?
我有以下代码片段:
#!/bin/ksh
source /users/some_user/.cshrc
Run Code Online (Sandbox Code Playgroud)
但是,运行它会产生source: not found错误.
我也试过使用dot像这样的运算符:
#!/bin/ksh
. /users/some_user/.cshrc
Run Code Online (Sandbox Code Playgroud)
但是,这也不能解决问题,尽管它不再给我source: not found错误.
获取.cshrc文件的正确方法是什么?