Advertisement
Guest User

masimaybegay

a guest
Jun 18th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. import java.io.BufferedWriter;
  2. import java.io.FileWriter;
  3. import java.io.IOException;
  4. import java.text.DecimalFormat;
  5. public class exercise6 {
  6.  
  7.     public static void main(String[] args) throws IOException {
  8.         // TODO Auto-generated method stub
  9.         {
  10.             writefile(69,"c:\\masi\\masiii.txt");
  11.         }
  12.     }
  13.  
  14.     private static void writefile(int n, String filename)throws IOException {
  15.         // TODO Auto-generated method stub
  16.         FileWriter writehandle = new FileWriter(filename);
  17.         DecimalFormat decimalformat = new DecimalFormat();
  18.         String st, formatted;
  19.             for(int i = 1;i<=n;i++)
  20.             {
  21.                 //decimalformat.setMinimumFractionDigits(i);
  22.                 //decimalformat.setMinimumFractionDigits(i);
  23.                 double x = Math.sqrt(i);
  24.                 st="%."+Integer.toString(i)+"f";
  25.                 formatted = String.format(st, x);
  26.                 //formatted = String.format("%.2f" x);
  27.                 writehandle.write(formatted + "\n");
  28.             }
  29.            
  30.        
  31.             writehandle.close();
  32.     }
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement