Advertisement
Guest User

Untitled

a guest
Sep 21st, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.util.*;
  2. import java.io.File;
  3. import java.io.FileNotFoundException;
  4. import java.util.InputMismatchException;
  5. import java.util.Scanner;
  6.  
  7. class AssignmentOne {
  8. public static void main(String[] args) throws FileNotFoundException, InputMismatchException {
  9.  
  10. File file = new File("Numbers.txt");
  11.  
  12. try {
  13. // Initialize Scanner with file
  14. Scanner in = new Scanner(file);
  15.  
  16. double[] arr = new double[9]; // Initialize array
  17. Arrays.fill(arr, 0.0); // Fills all the array positions with 0.0
  18.  
  19. // Maximum doubles is 10, but we are not sure if the text
  20. // file has 10 numbers so we use hasNextDouble
  21. int j = 0;
  22. while (in.hasNextDouble()) {
  23. try {
  24. arrayChecker(in.nextDouble());
  25. j++;
  26. } catch (InputMismatchException e) {
  27. System.out.println("Incompatable type ese");
  28. // arrayChecker(in.nextDouble());
  29. }
  30. }
  31.  
  32. in.close();
  33. } catch (FileNotFoundException e) {
  34. System.out.println("File does not exist!");
  35. }
  36. }
  37.  
  38. public static void arrayChecker(double arraySingleValue) {
  39. double[] array = new double[9];
  40. for (int i = 0; i < array.length; i++) {
  41. array[i] = arraySingleValue;
  42. }
  43. System.out.println(Arrays.toString(array));
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement