小编Loc*_*618的帖子

如何将数组写入Java文件

我一直在尝试将数组写入文件.我知道如何将整数或字符串写入文件但是让数组混淆了我.我现在正在使用它:

public static void write (String file, int[]x) throws IOException{
    BufferedWriter outputWriter = null;
    outputWriter = new BufferedWriter(new FileWriter(filename));
    outputWriter.write("hi");// Here I know i cant just write x[0] or anything. Do i need 
                             //to loop in order to write the array?
    outputWriter.newLine();
    outputWriter.flush();  
    outputWriter.close();  



}
Run Code Online (Sandbox Code Playgroud)

java arrays loops file bufferedwriter

6
推荐指数
2
解决办法
9万
查看次数

在Java中使用循环返回double

我试图从一个简单的for循环返回一个double.出于某种原因,我不断收到一条错误消息,指出该方法缺少一个return语句.

这是我的代码:

public static double quantitytable(){

    for(double x=1; x<=1000; x=x+100){    
           return x;
    }

}
Run Code Online (Sandbox Code Playgroud)

java loops for-loop return

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

java循环添加增量为100

这可能是一个愚蠢的问题,但我似乎无法弄明白.

如果我正在使用循环并启动一个int,如c为1,我希望它以100为增量显示数字1-2000.

1
100
200
300
400
500
etc.
Run Code Online (Sandbox Code Playgroud)

我会为c = c +写些什么?

java int loops for-loop while-loop

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

找到最大的随机数组

我已经尝试了一段时间来弄清楚如何找到随机数组的最大值.这是我正在调试的代码:截至目前,我得到的是数组中的一个值,但它不是最大值.

public static void main(String[] args) {
        System.out.println(intOfMaxInRange(randomIntArray(10), 1,30));
    }
     public static int random(int low, int high){
        int x=(int)(Math.random()*high+low);
        return x;
    }
    public static int[] randomArray(int n){
        int[] a = new int[n];
        for (int i = 0; i<a.length; i++) {
        a[i] = randomInt (1,30);
    }
        return a;
    }
    public static int intOfMax( int[] array){
        int max=array[0];
        for(int i=1;i<array.length;i++){
            if (array[i] > max) {
        }
        }
        return max;

    }
Run Code Online (Sandbox Code Playgroud)

java arrays debugging loops

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

标签 统计

java ×4

loops ×4

arrays ×2

for-loop ×2

bufferedwriter ×1

debugging ×1

file ×1

int ×1

return ×1

while-loop ×1