小编sam*_*333的帖子

反向单链表Java

有人能告诉我为什么我的代码有效吗?我想在java中反转单个链表:这是方法(不能正常工作)

public void reverseList(){
    Node before = null;
    Node tmp = head;
    Node next = tmp.next;
    while(tmp != null){
      if(next == null)
         return;
      tmp.next = before;
      before = tmp;
      tmp = next;
      next = next.next;
    }
}
Run Code Online (Sandbox Code Playgroud)

这是Node类:

public class Node{
   public int data;
   public Node next;
   public Node(int data, Node next){
      this.data = data;
      this.next = next;
   }
}
Run Code Online (Sandbox Code Playgroud)

在输入4-> 3-> 2-> 1我得到输出4.我调试它并正确设置指针,但我仍然不明白为什么它只输出4.

java singly-linked-list

29
推荐指数
4
解决办法
10万
查看次数

无法使用Linux打开JNLP文件?

我正在尝试加载jnlp文件.但是我有以下错误:Could not read or parse JNLP file.我已经读过这个问题可能会从Mozilla的首选项中修复:编辑 - >首选项 - >应用程序 - >"Java Web Start应用程序".但是我的应用程序中没有"Java Web Start应用程序"部分(我已经安装了icedtea-netx但在Application窗口中没有出现任何内容).我正在使用Linux薄荷.谁能告诉我怎么办?我参考的解决方案在这个论坛中:https://askubuntu.com/questions/91897/first-time-using-java-web-start-in-ubuntu-fatal-launch-exception

编辑:这是我的错误:

net.sourceforge.jnlp.LaunchException: Fatal: Read Error: Could not read or parse the JNLP file. 
    at net.sourceforge.jnlp.Launcher.fromUrl(Launcher.java:491)
    at net.sourceforge.jnlp.Launcher.launch(Launcher.java:283)
    at net.sourceforge.jnlp.runtime.Boot.run(Boot.java:211)
    at net.sourceforge.jnlp.runtime.Boot.run(Boot.java:53)
    at java.security.AccessController.doPrivileged(Native Method)
    at net.sourceforge.jnlp.runtime.Boot.main(Boot.java:177)
Caused by: java.io.IOException: Connection timed out
    at net.sourceforge.jnlp.JNLPFile.openURL(JNLPFile.java:282)
    at net.sourceforge.jnlp.JNLPFile.<init>(JNLPFile.java:212)
    at net.sourceforge.jnlp.JNLPFile.<init>(JNLPFile.java:188)
    at net.sourceforge.jnlp.JNLPFile.<init>(JNLPFile.java:173)
    at net.sourceforge.jnlp.JNLPFile.<init>(JNLPFile.java:159)
    at net.sourceforge.jnlp.Launcher.fromUrl(Launcher.java:477)
    ... 5 more
Caused by: 
java.io.IOException: Connection timed out
    at net.sourceforge.jnlp.JNLPFile.openURL(JNLPFile.java:282)
    at net.sourceforge.jnlp.JNLPFile.<init>(JNLPFile.java:212)
    at …
Run Code Online (Sandbox Code Playgroud)

java linux jnlp linux-mint

11
推荐指数
1
解决办法
2万
查看次数

为什么我们不能将计数排序应用于通用数组?

如果我们知道数组中的所有元素都是由给定数字限定的,计算排序是线性时间.如果我们采用一般数组,我们只能在线性时间扫描数组,找到数组中的最大值然后应用计数排序?

sorting algorithm counting-sort

5
推荐指数
2
解决办法
1064
查看次数

如何在 Java 中格式化双输入而不对其进行四舍五入?

我已经阅读了这个问题将双精度舍入到小数点后两位它显示了如何舍入数字。我想要的只是简单的格式,只打印两位小数。我所拥有的和我尝试过的:

double res = 24.695999999999998;
DecimalFormat df = new DecimalFormat("####0.00");
System.out.println("Value: " + df.format(res)); //prints 24.70 and I want 24.69
System.out.println("Total: " + String.format( "%.2f", res )); //prints 24.70
Run Code Online (Sandbox Code Playgroud)

所以当我有 24.695999999999998 我想把它格式化为 24.69

java double formatting

4
推荐指数
3
解决办法
8035
查看次数

Spring @ConditionalOnProperty 注释未按预期工作

我在属性文件中定义了一个属性: property=true

然后我有SomeClass.javaclass ,它应该在属性property设置为 true 时创建一个属性配置 bean 。

这是我的SomeClass课:

public class SomeClass {

  //this is the proerty which I set to true or false
  @Value("${property}")
  private String property;

  //this is the bean which needs to be created conditionally based on the property but at the moment it does not get created
  @Bean
  @ConditionalOnProperty(name="${property}", havingValue="true")
  public PropertyConfiguration propertyConfig() {
    // doesnt print anything because the bean does not get created
    System.out.print(property);
  } …
Run Code Online (Sandbox Code Playgroud)

java security spring annotations spring-boot

4
推荐指数
1
解决办法
1万
查看次数

我可以定义字符串数组并且在打字稿中未定义吗?

我已经定义在打字稿以下数组:let ids: string[] = [];。然后,当我尝试推送一个id(可能是未定义的)时,出现编译错误:ids.push(id);出现以下编译错误:

TS2345:“字符串|类型”的参数 未定义”不能分配给“字符串”类型的参数。类型“未定义”不能分配给类型“字符串”。

我可以创建未定义的字符串数组吗?

typescript

2
推荐指数
1
解决办法
477
查看次数

如何从 Java 的标准输入读取整数数组?

在标准输入的一行中,我有 3 种类型的整数:第一个整数是 id,第二个整数是 N - 某个数字,之后是 N 个整数,用一个空格分隔,我想将其存储在数组或 ArrayList 中。我如何使用 BufferedReader 来做到这一点?我有以下代码:

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String[] line = br.readLine().split(" ");
int ID = Integer.parseInt(line[0]);
int N = Integer.parseInt(line[1]);
Run Code Online (Sandbox Code Playgroud)

我的问题是有什么优雅的方法来读取该行的其余部分并将其存储到数组中吗?

java arrays bufferedreader

1
推荐指数
1
解决办法
3万
查看次数

为什么我无法计算双值?

我想计算0.95的值.这是我的方法:

public static final int VAR = 5; 
private static double getDouble(){
        double dis = (double)(VAR/100);
        dis = (double)(1-dis);
        return dis;
}
Run Code Online (Sandbox Code Playgroud)

但是,它输出1.0 ?? 如果我在main方法中键入相同的代码,我得到0.95.我的错误在哪里?

java double double-precision

0
推荐指数
1
解决办法
58
查看次数