Showing posts with label XML. Show all posts
Showing posts with label XML. Show all posts

JDOM script for generating an xml of fibonacci series

Posted by Shashank Krishna Saturday, August 1, 2009

The source is as follows:


import org.jdom.*;
import org.jdom.output.XMLOutputter;
import java.math.BigInteger;
import java.io.IOException;


public class FibonacciJDOM {

public static void main(String[] args) {

Element root = new Element("Fibonacci_Numbers");

BigInteger low = BigInteger.ONE;
BigInteger high = BigInteger.ONE;

for (int i = 1; i <= 5; i++) {
Element fibonacci = new Element("fibonacci");
fibonacci.setAttribute("index", String.valueOf(i));
fibonacci.setText(low.toString());
root.addContent(fibonacci);

BigInteger temp = high;
high = high.add(low);
low = temp;
}

Document doc = new Document(root);
// serialize it onto System.out
try {
XMLOutputter serializer = new XMLOutputter();
serializer.output(doc, System.out);
}
catch (IOException e) {
System.err.println(e);
}

}

}



The output is as follows:



1index="2">12
35

Are You Planning on Quitting Facebook? Why?

@Flickr

www.flickr.com

About Me

My Photo
Shashank Krishna
Bangalore, up, India
nothin much to say.........doin B.tech in IIIT allahabad loves bloggingn hacking.... :) and loooves blogging
View my complete profile

ads2

topads