Txerrinko

Ej1TablaMultiplicar

May 23rd, 2012
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.91 KB | None | 0 0
  1. package tanda1;
  2.  
  3. import java.io.File;
  4. import java.io.FileWriter;
  5. import java.io.IOException;
  6.  
  7. import org.jdom2.Document;
  8. import org.jdom2.Element;
  9. import org.jdom2.output.Format;
  10. import org.jdom2.output.XMLOutputter;
  11.  
  12. public class Ej1TablaMultiplicar {
  13.  
  14.     public static void main(String[] args) throws IOException {
  15.        
  16.         System.out.println("Introduce numero para multiplicar");
  17.         int num=Consola.leeInt();
  18.        
  19.         Element raiz=new Element("tabla");
  20.         Document doc=new Document(raiz);
  21.        
  22.         Element factr;
  23.         int mult=1;
  24.         for(int i=1;i<=10;i++)
  25.         {
  26.              mult = num*i;
  27.              
  28.              factr=new Element("Factor");
  29.              raiz.addContent(new Element("Fact").setText(String.valueOf(i)));
  30.              raiz.addContent(new Element("RSTD").setText(String.valueOf(mult)));
  31.         }
  32.         XMLOutputter salida=new XMLOutputter(Format.getPrettyFormat());
  33.         FileWriter fx=new FileWriter(new File("mult.xml"));
  34.         salida.output(doc,fx);
  35.     }
  36.  
  37. }
Advertisement
Add Comment
Please, Sign In to add comment