我试图检查我的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) 我的文件中有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) 我的数组共有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)