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:\\sentences.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. current.value=myTokens.nextToken();
  24. if(parent==null)
  25. parent.value=current.value;
  26. else
  27. {
  28. parent.next=current;
  29. parent=current;
  30. }
  31. }
  32. printList(tempParent.next);
  33. }
  34. }
  35. public static void printList(Node head)
  36. {
  37. Node ptr; //not pointing anywhere
  38. for(ptr=head;ptr!=null;ptr=ptr.next)
  39. System.out.print(ptr.value + " ");
  40. System.out.println();
  41. }
  42. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty