这里相当新,对java来说相当新。通过我的编程1课程和A弹簧,现在我在编程2,我终于挣扎了。通常情况下,我不会寻求帮助,如果您决定提供帮助,请不要牵着我的手。我主要是想找一个人来完成这项任务。 所以作业必须:
现在我遇到的问题是,我创建了2D数组读取文件并填充它,我只是不确定如何继续。我不希望你们中的任何人把答案交给我,或者重点是什么。关于如何进行的任何想法都会很棒,因为我一整天都在思考这些想法,但这些想法似乎都不符合我的意愿
代码:
import java.io.*;
import java.util.*;
public class Create2DArray {
public static int[][] array;
public static int dimension1, dimension2;
public static void main(String[] args) throws FileNotFoundException {
File inputFile = new File("sky image.txt");
Scanner scan = new Scanner(inputFile);
dimension1 = scan.nextInt();
dimension2 = scan.nextInt();
array = new int[dimension1][dimension2];
while (scan.hasNext()) {
for (int row = 0; row < dimension1; row++) {
for (int column = 0; column < dimension2; column++) {
array[row][column] = scan.nextInt();
System.out.printf("%4d ", array[row][column]);
}
System.out.println();
}
}
scan.close();
}
}
答案 0 :(得分:0)
没有完成所有工作,这是一个起点:
import java.awt.*;
import java.io.*;
import java.util.*;
public class Homework {
public static void main(String[] args) throws FileNotFoundException {
// run through the homework
// read the data (b)
int[][] array = loadData("sky image.txt");
// (c) lightSource
Point light = lightSource(array);
// check the answer here, is it right?
// (d) darkSource
// ... calls, checks for e-g here.
}
/** b. Reads the data file “sky image.txt” into the data structure. */
public static int[][] loadData(string fileName) {
// your code that is already in main, didn't re-write it just moved it
File inputFile = new File(fileName);
Scanner scan = new Scanner(inputFile);
int dimension1 = scan.nextInt();
int dimension2 = scan.nextInt();
int[][] array = new int[dimension1][dimension2];
while (scan.hasNext()) {
for (int row = 0; row < dimension1; row++) {
for (int column = 0; column < dimension2; column++) {
array[row][column] = scan.nextInt();
System.out.printf("%4d ", array[row][column]);
}
System.out.println();
}
}
sc.close();
return array;
}
/**
* c. A method called “lightSource” that receives the sky image data and returns the location of the brightest interior spot as a point.
* Use Java.awt.Point to represent a point.
*/
public static java.awt.Point lightSource( int[][] imageData ) {
// write code here
return new java.awt.Point( 0, 0 );
}
// put more methods here
}