我怎么知道我的shell是什么类型的?即,它是传统的sh,bash,ksh,csh,zsh等.
请注意,检查$SHELL或$0不起作用,因为$SHELL并非由所有shell设置,因此如果您从一个shell开始,然后启动另一个shell,您可能仍然使用旧的shell $SHELL.
$0只告诉你shell二进制文件的位置,但不告诉你/bin/sh是真正的Bourne shell还是bash.
我认为答案将是"尝试一些功能,看看有什么打破",所以如果有人能指出我这样做的脚本,那就太好了.
我已经开始使用setter而不是将参数放入默认构造函数中,因为它可以帮助我更好地组织代码
问题是我正在做的项目唯一的变量是一个字符串,我不确定我是否应该在声明中初始化它(作为一个全局变量?),在一个setter实例方法中,或者是否在它中初始化它类构造函数.
我想知道是否可能有任何问题,这个设置是否实例未初始化,直到它的setter使用:
class MyClass{
private String myString;
public MyClass(){
}
public void setStuff(String s){
this.myString=s;
}
}
Run Code Online (Sandbox Code Playgroud) 可能重复:
Java String.equals与==
我认为这将是一种结构化选择器方法的简洁方法,但输出不是前两个if语句而只输出最后一个
public int myPickerMethod(){
System.out.println("please select from the options ");
System.out.println("please select 1 for option 1 ");
System.out.println("please select 2 please select 2 for option 2");
String input = keyboard.readLine();
System.out.println("input = " + input);
if(input=="1"){
return 1;
}
else if(input=="2"){
return 2;
}
else{
return 42;
}
}
Run Code Online (Sandbox Code Playgroud)
这是终端的结果:
please select from the options
please select 1 for option 1
please select 2 please select 2 for option 2
1
input = 1
response = 42 …Run Code Online (Sandbox Code Playgroud) 如果是这样的话?
这会产生什么样的冲突?
我试图通过找出最佳实践来尽量减少你在java中可以获得的奇怪错误,所以希望使用它们可以让我免于麻烦!
我已经阅读了几个swing和awt线程但是注意到它们在一起使用的许多例子.
动机编辑:我被教导要同时使用swing和awt,我怀疑这可能不是最好的方法.
如何从2D数组中拉出第一列?我正在用这样的方法初始化我的数组
//Initialise the array with the values from the file
public static float[][] data(float[][] data, Scanner scan){
int count = 0;
for (int i=0;i<data.length;i++){
for (int j=0;j<data[0].length;j++){
count++;
if(count<data.length*data[0].length){
for(int k=0;k<2; k++){
data[i][j] = (float) IOUtil.skipToDouble(scan);
System.out.print(data[i][j] + " ");
}
System.out.println();
}
}
}
return data;
}
Run Code Online (Sandbox Code Playgroud)
这是我的测试文件的内容.(请记住文件可以是任何长度)
13.97 2.2
12.05 1.9
9.99 1.5
8.0 1.3
6.0 0.9
4.0 0.6
2.0 0.3
0.0 0.0
-2.0 -0.3
-4.0 -0.6
-6.02 -0.9
-8.0 -1.3
-9.99 -1.6
-12.03 -1.9
-13.98 -2.2
Run Code Online (Sandbox Code Playgroud)
在终端上,但问题是当我尝试调用左栏时,我得到了正确的列.我不确定这是否是因为右边的值是唯一存储或不存储的值. …
我是新手使用eclipse,我完全不知道为什么它不喜欢我的for循环的第一行
public Practice(int n) {
this.n=n;
for(int i=0; i<n; i++){
(int j=0; j<n; j++) {
this.decay=new double[i][j];
}
}
}
Run Code Online (Sandbox Code Playgroud) 在java中,什么会myArray.length在2D数组中引用?例如
double[][] myArray = new double[3][5];
Run Code Online (Sandbox Code Playgroud)
假设您想在数组上运行几个for循环而不将行和列放在参数中以获取它们的值,是否有一种巧妙的方法可以做到这一点?
我不知道第二个for循环是否会被认为是一个声明需要花括号的声明.
所以我要问的是这些for-loops:
for (int i=1;i<a.length;i++){
for (int j=0;j<a[i].length;j++){
a[i][j] = b[i][j]-c[i][j];
}
}
Run Code Online (Sandbox Code Playgroud)
意思是这些for-loops:
for (int i=1;i<a.length;i++)
for (int j=0;j<a[i].length;j++)
a[i][j] = b[i][j]-c[i][j];
Run Code Online (Sandbox Code Playgroud)