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,polyTerm;
  14. Node first=new Node();
  15. Node firstFull=new Node();
  16. while (inFile.hasNextLine())
  17. {
  18. line=inFile.nextLine();
  19. myTokens=new StringTokenizer(line);
  20. while (myTokens.hasMoreTokens())
  21. {
  22. polyTerm=myTokens.nextToken();
  23. first.value=polyTerm.substring(0,polyTerm.indexOf("x"));
  24. first.value2=polyTerm.substring(polyTerm.indexOf("^")+1);
  25. System.out.print(first.value + " " + first.value2);
  26. if (myTokens.nextToken()!=null)
  27. {
  28. polyTerm=myTokens.nextToken();
  29. first.next.value=polyTerm.substring(0,polyTerm.indexOf("x"));
  30. first.next.value2=polyTerm.substring(polyTerm.indexOf("^")+1);
  31. }
  32. }
  33. System.out.println();
  34. }
  35. }
  36. public static void printList(Node head)
  37. {
  38. Node ptr; //not pointing anywhere
  39. for(ptr=head;ptr!=null;ptr=ptr.next)
  40. System.out.print(ptr.value + " ");
  41. System.out.println();
  42. }
  43. }
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty