是否可以在Java 8中引入的Map.foreach函数中使用多个命令?
所以与其:
map.forEach((k, v) ->
System.out.println(k + "=" + v));
Run Code Online (Sandbox Code Playgroud)
我想做的事情如下:
map.forEach((k, v) ->
System.out.println(k)), v.forEach(t->System.out.print(t.getDescription()));
Run Code Online (Sandbox Code Playgroud)
让我们假设k是字符串而v是集合.
我在stackoverflow上查看了很多不同的主题,但到目前为止找不到任何有用的东西:/
所以这是我的问题.我正在写一个文件复制者.在读取文件时已发生此问题.我的测试文档有3行随机文本.所有这三行都应该用字符串数组写出来.问题是只有textdocument的第二行被写入数组,我无法弄清楚原因.已经调试过,但没有让我更进一步.
我知道有一个不同的解决方案,文件复制程序有不同的类等.但我真的想让它与我在这里使用的类一起运行.
String[] array = new String[5];
String datei = "test.txt";
public String[] readfile() throws FileNotFoundException {
FileReader fr = new FileReader(datei);
BufferedReader bf = new BufferedReader(fr);
try {
int i=0;
//String Zeile = bf.readLine();
while(bf.readLine() != null){
array[i] = bf.readLine();
// System.out.println(array[i]); This line is for testing
i++;
}
bf.close();
} catch (IOException e) {
e.printStackTrace();
}
return array;
Run Code Online (Sandbox Code Playgroud) double我想,可以代表的最高数字是非常高的.虽然以下代码抛出异常.这实际上是我的完整代码.
public class Summe {
public static void main(String[] args) {
System.out.println(summe(20000));
}
public static double summe(double s) {
return s == 0 ? s : s + summe(s-1);
}
}
Run Code Online (Sandbox Code Playgroud)
谢谢你到目前为止的答案.我的问题是:我如何使我的代码工作?
我有一个非常简单的问题,我无法弄清楚.
这就是我想要做的:
6 * (1/(1*1) + 1/(2*2) + 1/(3*3) + … + 1/(N*N))
Run Code Online (Sandbox Code Playgroud)
这是我的代码尝试,但不起作用.
int eingabe = 5;
double c = 0;
for (int i = 1 ; i<=eingabe ;i++) {
c += 1/(i*i);
}
c *= 6;
System.out.println(c);
Run Code Online (Sandbox Code Playgroud)
请帮帮我们!我需要做些什么来使代码工作?
java ×4
add ×1
arrays ×1
double ×1
filereader ×1
filewriter ×1
for-loop ×1
function ×1
java-8 ×1
lambda ×1
numbers ×1
while-loop ×1