Advertisement
sfrsnyz

Ворожейкин ЯП7

May 21st, 2021
32
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1.  
  2.  
  3. import java.io.File;
  4. import java.io.FileNotFoundException;
  5. import java.io.PrintWriter;
  6. import java.util.Scanner;
  7.  
  8. public class Main {
  9. public static void main(String[] args) throws FileNotFoundException {
  10. PrintWriter printWriter1=new PrintWriter(new File("First.txt"));
  11. PrintWriter printWriter2=new PrintWriter(new File("Second.txt"));
  12. PrintWriter printWriter3=new PrintWriter(new File("Third.txt"));
  13. Fileworker.sqrt(() -> { //извлечение корня 2 степени
  14. Scanner read= new Scanner(new File("In.txt"));
  15. while (read.hasNext()){
  16. int value=read.nextInt();
  17. double sqrt=Math.round(Math.sqrt(value)*100)/100.0;
  18. printWriter1.println(String.format("√%s=%s",value,sqrt));
  19. }
  20. printWriter1.close();
  21. read.close();
  22. });
  23. Fileworker.sqrt(() -> { //извлечение корня 3 степени
  24. Scanner read= new Scanner(new File("In.txt"));
  25. while (read.hasNext()){
  26. int value=read.nextInt();
  27. double sqrt=Math.round(Math.pow(value,1/3.0)*100)/100.0;
  28. printWriter2.println(String.format("∛%s=%s",value,sqrt));
  29. }
  30. printWriter2.close();
  31. read.close();
  32. });
  33. Fileworker.sqrt(() -> { //извлечение корня 4 степени
  34. Scanner read= new Scanner(new File("In.txt"));
  35. while (read.hasNext()){
  36. int value=read.nextInt();
  37. double sqrt=Math.round(Math.pow(value,1/4.0)*100)/100.0;
  38. printWriter3.println(String.format("∜%s=%s",value,sqrt));
  39. }
  40. printWriter3.close();
  41. read.close();
  42. });
  43. }
  44. }
  45.  
  46. //////////////
  47.  
  48. import java.io.FileNotFoundException;
  49.  
  50. public class Fileworker {
  51. public static void sqrt(Fileable fileable) throws FileNotFoundException {
  52. fileable.sqrtable();
  53. }
  54. }
  55.  
  56. ////////////
  57.  
  58. import java.io.FileNotFoundException;
  59.  
  60. public interface Fileable {
  61. void sqrtable() throws FileNotFoundException;
  62. }
  63.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement