Whats wrong with my code?
While compiling:
LinkedListInsertion.java:40: error: cannot find symbol
arr[i]=Integer.parseInt(br.readline());
^
symbol: method readline()
location: variable br of type BufferedReader
1 error
code is as follos:
import java.io.*;
public class LinkedListInsertion{
Node head;
static class Node{
Node next;
int data;
Node(int data,LinkedListInsertion list){
this.data = data;
next = null;
}
}
public static LinkedListInsertion insert(LinkedListInsertion list,int data){
Node new_node=new Node(data,list);
Node last;
if(list.head==null){
list.head = new_node;
}
else{
last = list.head;
while(last.next!=null){
last = last.next;
}
last.next = new_node;
}
return list;
}
public static void printList(LinkedListInsertion list){
Node currNode = list.head;
System.out.print("LinkedListAB: ");
while (currNode != null){
System.out.print(currNode.data + " ");
currNode = currNode.next;
}
}
public static void main(String[] args){
int[] arr=new int[5];
LinkedListInsertion mylist=new LinkedListInsertion();
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
for(int i=1; i<=5; i++){
arr[i]=Integer.parseInt(br.readline());
mylist = insert(mylist,arr[i]);
}
printList(mylist);
}
}