可能重复:
参数命名:filename还是fileName?
你用什么 - 文件名或文件名?JDK中的类使用小写'n',例如FilenameFilter,因此,为了保持一致性,我也这样做.但我认为,正确的方法应该是fileName(如在C#中).
如何获取java中字母的数字位置?
假设通过命令提示我输入了abc然后作为输出我需要得到123如何获得java中字母的数字位置?
提前致谢.
我正在尝试使用Java 7的 ThreadLocalRandom,并发现它在多个线程中生成完全相同的随机数.
这是我的代码,我创建了5个线程,每个线程打印出5个随机数:
//5 threads
for(int i = 0; i < 5 ; i++) {
final Thread thread = new Thread() {
@Override
public void run() {
System.out.print(Thread.currentThread().getName()+":");
//each thread prints 5 random numbers
for(int j = 0 ; j < 5; j++) {
final int random = ThreadLocalRandom.current().nextInt(1,100);
System.out.print(random + ",");
}
System.out.println();
}
};
thread.start();
thread.join();
}
Run Code Online (Sandbox Code Playgroud)
输出:
Thread-0:1,93,45,75,29,
Thread-1:1,93,45,75,29,
Thread-2:1,93,45,75,29,
Thread-3:1,93,45,75,29,
Thread-4:1,93,45,75,29,
Run Code Online (Sandbox Code Playgroud)
为什么我为每个线程和每次执行程序获得相同的随机数?
在通过另一个成功的命令传送后,如何从unix命令行应用程序中获取正确的返回码?
详细说明,情况如下:
$ tar -cEvhf - -I ${sh_tar_inputlist} | gzip -5 -c > ${sh_tar_file} -- when only the tar command fails $?=0
$ echo $?
0
Run Code Online (Sandbox Code Playgroud)
而且,我希望看到的是:
$ tar -cEvhf - -I ${sh_tar_inputlist} 2>${sh_tar_error_file} | gzip -5 -c > ${sh_tar_file}
$ echo $?
1
Run Code Online (Sandbox Code Playgroud)
有谁知道如何做到这一点?
我是否有任何令人信服的理由立即升级到Maven 3?发行说明中没有什么突出的.
你升级到Maven 3了吗?如果是这样,你看到了什么好处?
给定一个单词W,我想从/ usr/dict/words中找到包含W中字母的所有单词.例如,"bat"应该返回"bat"和"tab"(但不是"table").
这是一个涉及对输入词进行排序和匹配的解决方案:
word=$1
sortedWord=`echo $word | grep -o . | sort | tr -d '\n'`
while read line
do
sortedLine=`echo $line | grep -o . | sort | tr -d '\n'`
if [ "$sortedWord" == "$sortedLine" ]
then
echo $line
fi
done < /usr/dict/words
Run Code Online (Sandbox Code Playgroud)
有没有更好的办法?我更喜欢使用基本命令(而不是perl/awk等),但欢迎所有解决方案!
为了澄清,我想找到原始单词的所有排列.不允许添加或删除字符.
我想在while循环中进行切换,在每个switch语句中断while循环停止并请求输入如F,R,C,Q.下面的语句有效,但语句不会中断.请帮忙
public static void main(String[] args) throws IOException {
// start both with 1 point
int goodTotal = 50;
int monTotal = 50;
// input switch statement
while (goodTotal > 0 && monTotal > 0) {
System.out.print("Type a letter: ");
System.out.println("\n");
System.out.print("F: Go out and Fight ");
System.out.println("\n");
System.out.print("R: Rest ");
System.out.println("\n");
System.out.print("C: Check Stats ");
System.out.println("\n");
System.out.print("Q: Quit ");
int input = System.in.read();
System.out.println("You typed: " + (char) input);
switch (input) {
case 'f':
System.out.println("Continue the game");
break;
case …Run Code Online (Sandbox Code Playgroud) Eclipse Helios中有哪些新的和值得注意的功能,尤其是Java IDE?
我浏览了网站,但找不到任何发行说明.
谢谢
我正在使用apache derby作为我的数据库.我能够在数据库中执行插入操作.以下是试图显示我唯一的表'MAINTAB'的内容的代码的摘录.java.sql.Connection的实例是'dbconn'.
ResultSet word;
Statement query;
String getData="SELECT THEWORD FROM MAINTAB";
try{
System.out.println(dbconn.getAutoCommit());
query = dbconn.createStatement();
word = query.executeQuery(getData);
query.close();
dbconn.setAutoCommit(false);
System.out.println(dbconn.getAutoCommit());
for(;word.next();)
System.out.println(word.getString(1));
}catch(Throwable e){
System.out.println("Table fetch failed or result data failed");}
Run Code Online (Sandbox Code Playgroud)
以下是输出.
org.apache.derby.jdbc.EmbeddedDriver loaded.
Database testDB connected
true
false
Table fetch failed or result data failed
---SQLException Caught---
SQLState: XCL16
Severity: 20000
Message: ResultSet not open. Operation 'getString' not permitted. Verify that autocommit is OFF.
java.sql.SQLException: ResultSet not open. Operation 'getString' not permitted. Verify that autocommit is OFF. …Run Code Online (Sandbox Code Playgroud)