我有一个用Java进行二进制搜索的程序.在为数组输入后,'for-each'循环似乎没有增加计数器变量.但是,它确实适用于常规的'for'循环.为什么'for-each'循环在这种情况下不能增加计数器?
import java.util.Scanner;
public class binarySearch {
public static int rank(int key, int[] a) {
int lo = 0;
int hi = a.length - 1;
while (lo <= hi) {
int mid = lo + (hi - lo) / 2;
if (key > a[mid])
lo = mid + 1;
else if (key < a[mid])
hi = mid - 1;
else
return mid;
}
return -1;
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
System.out.println("Enter the key …Run Code Online (Sandbox Code Playgroud) 我正在将我的 Maven JavaFX 应用程序从 Java 8 迁移到 Java 11。我将 pom.xml 中的插件更新为最新的(兼容 Java 11 的)插件。编译运行良好,在“目标”文件夹下的正确目录中为我提供了 jar 以及所有依赖项和模块,但是当我尝试运行 jar 文件时,我收到了可怕的“缺少 JavaFX 应用程序类”错误。无论我如何尝试更改插件配置 - 我总是收到此错误消息,并且应用程序将无法运行。
现在,更多发现: 1. 主类确实位于类下的正确文件夹和 jar 中。2. Manifest 文件位于正确的位置,并且包含主类属性(在 Java 8 下工作正常)。
这是相关部分
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>11</source>
<release>11</release>
<showWarnings>true</showWarnings>
<showDeprecation>true</showDeprecation>
<compilerVersion>11</compilerVersion>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>7.0</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>false</addClasspath>
<mainClass>${mainClass}</mainClass>
</manifest>
<manifestEntries>
<JavaFX-Application-Class>${mainClass}</JavaFX-Application-Class>
</manifestEntries>
</archive>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
</configuration>
</plugin>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-libs</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/libs</outputDirectory>
<includeScope>runtime</includeScope>
<excludeGroupIds>org.openjfx</excludeGroupIds> …Run Code Online (Sandbox Code Playgroud) 在java 8中,以下之间有什么真正的区别:
try (OutputStream os = Files.newOutputStream(path)) {
[...]
}
Run Code Online (Sandbox Code Playgroud)
和
try (OutputStream os = new BufferedOutputStream(Files.newOutputStream(path))) {
[...]
}
Run Code Online (Sandbox Code Playgroud)
我阅读了这个SO question and answers,但它让我很困惑。
PS:Java 11 有什么变化?
我尝试这样做gradle build,但它给了我这个错误:
包 com.sun.org.apache.xerces.internal.dom 在模块 java.xml 中声明,该模块不会导出它
我检查过gradle dependencies,但没有人使用java.xml
我们仅在代码的一部分中使用 ElementNSImpl(我不知道为什么......)。不管怎样,当我尝试切换到 Java 11 Zulu 时,Eclipse 给了我这个错误:
com.sun.org.apache.xerces.internal.dom.ElementNSImpl 类型不可访问
对于 OpenJDK 8,我们必须使用以下命令导入它xerces:xercesImpl:2.6.2-jaxb-1.0.6
我用 Eclipse 检查了该类,它是一个公共类,位于 Zulu 11 jar 下。
由于 Oracle JDK 需要为生产环境付费,我想知道 OpenJDK/AdoptOpenJDK 是否也给我同样的稳定性。我读到 Oracle 正在开发 OpenJDK,因为我建议 OpenJDK 11 也与 Oracle JDK 11 一样稳定。但我没有这方面的经验。另一个问题是:稳定系列 11 的 OpenJDK 和 AdoptOpenJDK 之间的主要区别是什么?您更喜欢在生产环境中使用什么?因此,如果有人能给我建议,我会很高兴。
我在 ubuntu 18.04 系统中安装了 JDK 8,现在想使用此将其升级到 JDK 11 。我只是想知道这是否会产生任何问题。升级时会删除旧版本吗(实际上我希望旧版本自行删除)?
我有一个方法,效果很好。这就是它的样子。
private boolean roomWithMoreThanTenFurnitures(Building building) {
if (building != null && building.hasRooms()) {
for (Room room : building.getRooms()) {
if (room.getFurnitures.size() > 10) {
return true;
}
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我想把它切换到 Lambda。uo 是用 shell 进来的,但是我不知道外面如何填写 if(条件) return true 或 return false。
building.getRooms().forEach(room -> {
//??
});
Run Code Online (Sandbox Code Playgroud) 我正在处理这个问题:
produto.setQuantidade(new Short("7"));
Run Code Online (Sandbox Code Playgroud)
Short显示已弃用,并带有标记。如何为以上 Java 9 版本更新此内容?(现在,我有 Java 11)
这是我的代码:
List<String[]> salaries = getSalariesByMonth();
//I am using the old way to print the data
for (String[] obj : rates) {
System.out.println("User name: "obj[0]+"--"+"Salary: "+obj[1]); //obj[0] is NAME, obj[1] is SALARY
}
//I am trying to use this way to print the data but unable to do so.
salaries.forEach(s-> System.out.println("print NAME and SALARY"));
Run Code Online (Sandbox Code Playgroud)
如何使用 Lambda 打印包含字符串数组的列表。先感谢您。
我需要从源代码交叉编译这个 OpenJava 分支https://gitlab.com/gosjava/11/openjdk/-/tree/master/ - 对于 aarch64-linux-gnu devkit 目标:\n为此我安装了 java 10.0.2作为主机 JDK 然后运行“./configure”
\n\xe2\x94\x94\xe2\x94\x80$ ./configure \n...\nconfigure: Potential Boot JDK found at /home/katya/java is incorrect JDK version (Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true); ignoring\nconfigure: (Your Boot JDK version must be one of: 10 11)\nchecking for javac... /home/katya/java/bin/javac\nchecking for java... /home/katya/java/bin/java\nconfigure: Found potential Boot JDK using java(c) in PATH\nconfigure: Potential Boot JDK found at /home/katya/java is incorrect JDK version (Picked up _JAVA_OPTIONS: -Dawt.useSystemAAFontSettings=on -Dswing.aatext=true); ignoring\nconfigure: (Your Boot JDK version must be one …Run Code Online (Sandbox Code Playgroud) java ×10
java-11 ×10
java-8 ×2
adoptopenjdk ×1
azul-zulu ×1
deprecated ×1
eclipse ×1
file ×1
javafx ×1
lambda ×1
maven ×1
openjdk-11 ×1
outputstream ×1
short ×1