klasscho

Untitled

Nov 25th, 2019
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.59 KB | None | 0 0
  1. package com.company;
  2.  
  3. import java.io.BufferedReader;
  4. import java.io.File;
  5. import java.io.FileReader;
  6. import java.io.FileWriter;
  7. import java.util.Scanner;
  8.  
  9.  
  10. public static void ReadFromFile (int [][] Matrixx, String FName, int Row, int Col) throws
  11. Exception {
  12. String line;
  13. String [] Numb;
  14. BufferedReader buff = new BufferedReader(new FileReader(FName));
  15. for (int i = 0; i <= Row; i++) {
  16. line = buff.readLine();
  17. numbers = line.split(" ");
  18. for (int j = 0; j <= Col; j++) {
  19. Matrixx[i][j] = Integer.parseInt(Numb[j]);
  20. }
  21. }
  22. buff.close();
  23. }
  24.  
  25. public static int MatrixRowSize(String FName) throws Exception {
  26. int count = 0;
  27. FileReader MyFile = new FileReader(FName);
  28. BufferedReader buff = new BufferedReader(MyFile);
  29. while (buff.readLine() != null) {
  30. count++;
  31. }
  32. FileIn.close();
  33. return (count);
  34. }
  35.  
  36. public static int MatrixColSize(String FName) throws Exception {
  37. String line;
  38. String[] Numb;
  39. int count = 0;
  40. FileReader MyFile = new FileReader(FName);
  41. BufferedReader buff = new BufferedReader(MyFile);
  42. line = buff.readLine();
  43. numbers = line.split(" ");
  44. for (int i = 0; i < numbers.length; i++)
  45. count++;
  46. FileIn.close();
  47. return (count);
  48. }
  49.  
  50. public static void WriteToFile (float Arr[], String FName, int Row, int Col)
  51. throws Exception {
  52. FileWriter FileOut = new FileWriter(FileName);
  53. for (int i = 0; i <= Row; i++) {
  54. FileOut.write(Arr[i] + " ");
  55. }
  56. FileOut.write("\n");
  57. }
  58. FileOut.close();
  59. System.out.println("Saved to file: " + FName);
  60. }
  61. }
  62.  
  63. public static void Average(int [][] Matrixx, int Col, int Row)
  64. {
  65. int i, j;
  66. float avg;
  67. for (j = 0; j < Col; j++) {
  68. for (i = 0; i < Row; i++)
  69. avg += Matrixx[j][i];
  70. printf("%.4f ", avg / row);
  71. }
  72. return 0;
  73. }
  74.  
  75. public static void float AverageOutput(int [] Arr; int Row){
  76. int i;
  77. float avg;
  78. for (int i = 0, i < Row, i++){
  79. printf("%.4f ", avg / row);
  80. }
  81. }
  82.  
  83. public static void MatrixOutput (int [][] Matrixx, int Row, int Col) {
  84. for (int i = 0; i <= Row; i++) {
  85. for (int j = 0; j <= Col; j++) {
  86. System.out.printf("%d ", Matrixx[i][j]);
  87. }
  88. System.out.println();
  89. }
  90. System.out.println();
  91. }
Advertisement
Add Comment
Please, Sign In to add comment