Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.InputMismatchException;
- import java.util.Scanner;
- class AssignmentOne {
- public static void main(String[] args) throws FileNotFoundException, InputMismatchException {
- File file = new File("Numbers.txt");
- try {
- // Initialize Scanner with file
- Scanner in = new Scanner(file);
- double[] arr = new double[9]; // Initialize array
- Arrays.fill(arr, 0.0); // Fills all the array positions with 0.0
- // Maximum doubles is 10, but we are not sure if the text
- // file has 10 numbers so we use hasNextDouble
- int j = 0;
- while (in.hasNextDouble()) {
- try {
- arrayChecker(in.nextDouble());
- j++;
- } catch (InputMismatchException e) {
- System.out.println("Incompatable type ese");
- // arrayChecker(in.nextDouble());
- }
- }
- in.close();
- } catch (FileNotFoundException e) {
- System.out.println("File does not exist!");
- }
- }
- public static void arrayChecker(double arraySingleValue) {
- double[] array = new double[9];
- for (int i = 0; i < array.length; i++) {
- array[i] = arraySingleValue;
- }
- System.out.println(Arrays.toString(array));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement