如何将多个(i,j)形式的坐标存入到一个二维数组里面,用java实现,求代码实现~~请高手受累帮忙
解决方案 »
- jtable类会改变日文片假名的输出
- Cannot create JDBC driver of class '' for connect URL 'jdbc:mysql://127.0.0.1/my
- 不用循环~如何输出1~100?
- java里的scanf("%d,%s",i,s)是哪个函数?
- [请教]关于汉字(HZ)编码的介绍,或者注意点!!!
- Applet用microsoft sdk for java编译通过,但repaint 不能触发 paint,是编译器问题吗?
- byte[]到底可以有多长?
- java打印??新手请教!
- 请问Clane:C和java通过Socket通讯的问题
- 请问如何用WEB方式调用java并获取其返回值???(如何获取其返回值)
- 关于“吞食”异常,这个概念不太明白,请各位帮忙解答下~~~
- table刷新问题
不知道我说明白了么?
你坐标是以一维数组的形式给出的吗?{i1,j1,i2,j2,……}?
你想存入的二维数组是什么形式的?
楼主要提供你的Input和Output,我们才能提供Process
public class test{
public static void main(String[] args){
int [] arr1 = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}; // 假设这是你的坐标(1,2),(3,4),……
int [][] arr2 = new int[arr1.length / 2][2]; // 创建一个行为原数组长度一半,列为2的二维数组
for (int i = 0; i < arr1.length; i++) {
// 遍历原数组,赋值给新数组
arr2[i / 2][i % 2] = arr1[i];
}
for (int i = 0; i < arr2.length; i++ ) {
for (int j = 0; j < arr2[i].length; j++ ) {
System.out.print(arr2[i][j] + " ");
}
System.out.println();
}
} }输出1 2
3 4
5 6
7 8
9 10
for (int j = 0; j < width; j++) {
int k = i * width + j;
if((i > 22) && (i < height - 22)){
if (ImageSource[k] == Constants.BLACK) {
for(int a = 2; a < 7; a++){
if(ImageSource[(i + a) * width + j] == Constants.BLACK){
for(int b = 2; b <= 5; b ++){
if(ImageSource[(i + a + b) * width + j] == Constants.WHITE){
for(int c = 1; c <= 9; c++){
if(ImageSource[(i + a + b + c) * width + j] == Constants.BLACK){
grayArray[k] = Constants.RED;
}
}
}
}
}
}
for(int x = 2; x < 8; x++){
for(int x1 = x + 2; x1 < 10; x1++){
for(int m = 2; m < 8; m++){
for(int n = m + 1; n < 8; n++){
for(int y = 2; y < 8; y++){
for(int y1 = 2; y1 < 8; y1++){
if (ImageSource[k + x] == Constants.WHITE) {
grayArray[k] = Constants.RED;
}
}
}
}
}
}
}
} else {
grayArray[k] = Constants.RED;
}
// if(grayArray[k] == Constants.RED){
//
// int array[][] = new int[20][2];
//
// for(int len = 0; len < array.length; len ++){
// array[len] = grayArray[k];
// for(int len1 = 0; len1 < array[len].length; len1++){
// array[len][len1] = grayArray[k][]
// }
// }
//
// System.out.println("i = " + i + ",j = " + j);
// for(int a = 0; a < 5; a++){
// if(grayArray[k] == Constants.RED){
// System.out.println("i = " + i + "; j = " + j);
// }
// }
// }
}
}
}
return grayArray;
}
能行么?
//...处理后
arr2[][] = {{1,2},{3,4},{5,6},{7,8},{9,10}}
for (int i = 0; i < arr1.length; i++) {
// 遍历原数组,赋值给新数组
arr2[i / 2][i % 2] = arr1[i];
}