fork download
  1. /* package codechef; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8.  
  9. class Node
  10. {
  11. int val;
  12. Node next;
  13. Node(int n)
  14. {
  15. val=n;
  16. }
  17. }
  18. class Ideone
  19. {
  20. Node start=null;
  21. public static void main (String[] args) throws java.lang.Exception
  22. {
  23. // your code goes here
  24. Ideone c=new Ideone();
  25. c.create();
  26. c.trav();
  27. }
  28.  
  29. void create()throws IOException
  30. {
  31. char ch='y';
  32. Node temp,curr=null;
  33.  
  34. while(ch=='y')
  35. {
  36. System.out.println("Enter number");
  37.  
  38. temp=new Node(Integer.parseInt(br.readLine()));
  39. temp.next=null;
  40. if(start==null)
  41. {
  42. start=temp;
  43. curr=temp;
  44.  
  45. }
  46. else
  47. {
  48. curr.next=temp;
  49. curr=temp;
  50. }
  51. ch=(char)br.read();
  52. }
  53. }
  54.  
  55. void trav()
  56. {
  57. Node temp=start;
  58. while(temp!=null)
  59. {
  60. System.out.println(temp.val);
  61. temp=temp.next;
  62. }
  63. }
  64. }
  65.  
Runtime error #stdin #stdout #stderr 0.05s 711168KB
stdin
Standard input is empty
stdout
Enter number
stderr
Exception in thread "main" java.lang.NumberFormatException: null
	at java.lang.Integer.parseInt(Integer.java:542)
	at java.lang.Integer.parseInt(Integer.java:615)
	at Ideone.create(Main.java:39)
	at Ideone.main(Main.java:25)