Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lab1;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.io.IOException;
- import java.util.Arrays;
- import java.util.Scanner;
- /**
- *
- * @author Gregory
- */
- public class Lab1 {
- /**
- * @param args the command line arguments
- */
- public static void main(String[] args) throws FileNotFoundException {
- try {
- File file = new File("ELEVATIONS.txt");
- Scanner inputFile = new Scanner(file);
- int rowsCount = 0;
- int colsCount = 0;
- int radius = 0;
- if (inputFile.hasNext()) {
- rowsCount = inputFile.nextInt();
- } else {
- System.out.println("Error cannot read rows count");
- return;
- }
- if (inputFile.hasNext()) {
- colsCount = inputFile.nextInt();
- } else {
- System.out.println("Error cannot read cols count");
- return;
- }
- if (inputFile.hasNext()) {
- radius = inputFile.nextInt();
- } else {
- System.out.println("Error cannot read radius");
- return;
- }
- int[][] numbers = new int[rowsCount][colsCount];
- for (int row = 0; row < numbers.length; row++) {
- for (int col = 0; col < numbers[row].length; col++) {
- numbers[row][col] = inputFile.nextInt();
- }
- }
- inputFile.close();
- for (int row = 0; row < numbers.length; row++) {
- for (int col = 0; col < numbers[row].length; col++) {
- System.out.printf(numbers[row][col] + " ");
- }
- System.out.println();
- }
- int[] lowestValueInData = lowestVal(numbers);
- int[] allPeaks = localPeaks(numbers, radius);
- System.out.println("the lowest data in the set is: " + lowestValueInData[0]);
- System.out.println("its frequency is: " + lowestValueInData[1] + " times.");
- System.out.println("all peaks: " + allPeaks);
- //System.out.println("Local peaks: " localPeaks());
- } catch (IOException ex) {
- System.out.println(ex);
- }
- }
- public static int[] lowestVal(int numbers[][]) {
- int lowestValue = numbers[0][0];
- int numOfTimes = 0;
- for (int row = 0; row < numbers.length; row++) {
- for (int col = 0; col < numbers[row].length; col++) {
- if (numbers[row][col] < lowestValue) {
- lowestValue = numbers[row][col];
- numOfTimes = 1;
- } else if (lowestValue == numbers[row][col]) {
- numOfTimes++;
- }
- }
- }
- return new int[]{lowestValue, numOfTimes};
- }
- public static int[] localPeaks(int numbers[][], int radius) {
- //int peaksArr[] = new int[0]; //?
- //removes out of bounds exception, creates big square
- for (int rowTopLeft = radius; rowTopLeft < numbers.length - radius; rowTopLeft++) {
- for (int colTopLeft = radius; colTopLeft < numbers[rowTopLeft].length - radius; colTopLeft++) {
- int x = numbers[rowTopLeft][colTopLeft];
- if (x > 94850) { //if x is larger than 94850 search the radius otherwise skip
- //little square
- int[][] newStartPoint = numbers[rowTopLeft - radius][colTopLeft - radius];
- for (int row = rowTopLeft; row < (rowTopLeft + radius * 2 + 1); row++) { //search radius of little square
- for (int col = colTopLeft; col < (colTopLeft + radius * 2 + 1); col++) {
- }
- }
- }
- }
- }
- }
- }
- // return peaksArr;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement