fork download
  1. import java.util.Scanner;
  2.  
  3. class LinkedListNode {
  4.  
  5. int data;
  6. LinkedListNode next;
  7.  
  8. LinkedListNode(int val) {
  9. data = val;
  10. }
  11. }
  12.  
  13.  
  14. public class temp {
  15.  
  16.  
  17. public static void printLL(LinkedListNode head) {
  18.  
  19. LinkedListNode temp = head;
  20.  
  21. while (temp != null) {
  22.  
  23. System.out.print(temp.data + " -> ");
  24. temp = temp.next;
  25. }
  26.  
  27. }
  28.  
  29. public static LinkedListNode inputLL() {
  30.  
  31.  
  32. Scanner sc = new Scanner(System.in);
  33.  
  34. int data = sc.nextInt();
  35.  
  36. LinkedListNode head = null;
  37. LinkedListNode tail = null;
  38.  
  39.  
  40. while (data != -1) {
  41.  
  42. LinkedListNode newNode = new LinkedListNode(data);
  43.  
  44. if (head == null) {
  45.  
  46. head = newNode;
  47. tail = newNode;
  48. }
  49.  
  50. else {
  51. tail.next = newNode;
  52. tail = tail.next;
  53. }
  54.  
  55. data = sc.nextInt();
  56. }
  57.  
  58. return head;
  59. }
  60.  
  61. public static void main(String[] args) {
  62.  
  63.  
  64. LinkedListNode head = inputLL();
  65.  
  66. printLL(head);
  67.  
  68. }
  69. }
  70.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:14: error: class temp is public, should be declared in a file named temp.java
public class temp {
       ^
1 error
stdout
Standard output is empty