HTMLDemo.java Source code

Java tutorial

Introduction

Here is the source code for HTMLDemo.java

Source

import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.text.DecimalFormat;

public class HTMLDemo {

    public static void main(String[] a) throws IOException {
        PrintWriter pw = new PrintWriter(new FileWriter("test.html"));
        DecimalFormat ff = new DecimalFormat("#0"), cf = new DecimalFormat("0.0");
        pw.println("<TABLE BORDER><TR><TH>Fahrenheit<TH>Celsius</TR>");
        for (double f = 100; f <= 400; f += 10) {
            double c = 5 * (f - 32) / 9;
            pw.println("<TR ALIGN=RIGHT><TD>" + ff.format(f) + "<TD>" + cf.format(c));
        }
        pw.println("</TABLE>");
        pw.close(); // Without this, the output file may be empty
    }
}