fork download
  1. import java.io.*;
  2. import java.util.*;
  3. public class PolynomialAddition
  4. {
  5. static File dataInpt;
  6. static Scanner inFile;
  7.  
  8. public static void main(String[] args) throws IOException
  9. {
  10. dataInpt=new File("C:\\llpoly.txt");
  11. inFile=new Scanner(dataInpt);
  12. StringTokenizer myTokens;
  13. String line, sentence;
  14. Node parent = new Node();
  15. while (inFile.hasNextLine())
  16. {
  17. Node tempParent = parent;
  18. line=inFile.nextLine();
  19. myTokens=new StringTokenizer(line);
  20. while (myTokens.hasMoreTokens())
  21. {
  22. Node current = new Node();
  23. String polyTerm=myTokens.nextToken();
  24.  
  25. current.value=polyTerm.substring(0,polyTerm.indexOf("x"));
  26. current.value2=polyTerm.substring(polyTerm.indexOf("^")+1);
  27.  
  28. if(parent==null)
  29. parent.value=current.value;
  30. else
  31. {
  32. parent.next=current;
  33. parent=current;
  34. }
  35. }
  36. printList(tempParent.next);
  37. }
  38. }
  39. public static void printList(Node head)
  40. {
  41. Node ptr; //not pointing anywhere
  42. for(ptr=head;ptr!=null;ptr=ptr.next)
  43. System.out.print(ptr.value + " " + ptr.value2 + " ");
  44. System.out.println();
  45. }
  46. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty