SHARE
TWEET

notbnotb

a guest Jun 18th, 2019 63 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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,"textfile");
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top