小编Len*_*all的帖子

当我更改数组的元素时,为什么我的方法不返回false?

我试图检查我的2D阵列是否对称.我写了一个方法来检查数组是否对称.它总是返回true,即使我更改了输入数组中的元素.我究竟做错了什么?

这是我的代码:

public class learnigBoolean
{
    public static void main(String[] args)
    {
        int[][] array = {
            { 1,  1,  4, -1},
            { 1,  5,  0, -1},
            { 4,  0,  1, -4},
            {-1, -1,  4, 10}
        };

        System.out.println(symetrisk(array));
    }

    public static boolean symetrisk(int[][] f)
    {
        for (int out = 0; out < f.length; out++) {
            for (int in = 0; in < f[out].length; in++) {
                if (f.length == f[out].length && f[out][in] == f[out][in]) {
                    return true;
                }
            }
        }
        return false; …
Run Code Online (Sandbox Code Playgroud)

java arrays boolean

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

如何写出随机名称?

我的文件中有8个名字,每一行只有一个名字.

我试图随意写出其中一个名字.我写了一些代码,但我不知道我将如何继续.(我试图解决这个问题而不使用数组,因为我们还没有学习).我的名单上有这些名字;

patrica
natascha
lena
sara
rosa
kate
funny
ying
Run Code Online (Sandbox Code Playgroud)

而且我想system.out.println随意写出一个名字

这是我的代码:

BufferedReader inputCurrent = new BufferedReader(new FileReader("aText.txt"));

    String str;
    int rowcounter =0;
    int mixNum =0;
    String strMixNum=null;
    while((str = inputCurrent.readLine())!= null){
        rowcounter++; 
        mixNum = rnd.nextInt(rowcounter)+1;
        //strMixNum = ""+strMixNum;

        String str2;
        while((str2 = inputCurrent.readLine())!= null){
            // i dont know what i s shall write here
            System.out.println(str2);
        }
    }

    inputCurrent.close();
Run Code Online (Sandbox Code Playgroud)

java random algorithm

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

使用涉及每个元素索引的计算在数组中分配值

我的数组共有10个指标,我想设置array[0] = 1/1,array[1] = 1/2,array[2] = 1/3,array[4] = 1/4等等.

计算后我想显示元素 Sytem.out.println();

我究竟做错了什么?

public static void main(String[] args) {
    final int VALUE =1;
    int[] array = new int[10];
    int counter=10;
    double result =0;
    for(int i =0; i<array.length; i++)
    {
        array[0]=VALUE/i;
        array[1]=VALUE/i;
        array[2]=VALUE/i;
        array[3]=VALUE/i;
        array[4]=VALUE/i;
        array[5]=VALUE/i;
        array[6]=VALUE/i;
        array[7]=VALUE/i;
        array[8]=VALUE/i;
        array[9]=VALUE/i;

    System.out.println( array[0] +" " + array[1] +" " + array[2] +" " + array[3]+" " +  array[4]+" "+array[5]+" " +array[6] +" " + array[7]+" …
Run Code Online (Sandbox Code Playgroud)

java arrays algorithm math

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

标签 统计

java ×3

algorithm ×2

arrays ×2

boolean ×1

math ×1

random ×1