java - Linked list of characters displaying as numbers -


so i'm trying make linked list of characters, first i'm going point out we're not allowed use built in methods linked lists in java already. when add characters , try display them, gives me list of numbers. why happening?

class node{         int data;         node next;         public node(character x){             data = x; next = null;         }         public node next(){return next;}         public void setnext(node p){             next = p;         }         public void set(character x){data = x;}         public int data(){return data;}     }        class reader{             node head = null;//empty list             public void add(character x){ //add @ head                 node nw = new node(x);                 nw.setnext(head);                 head = nw;             }             public void display(){                 node k = head;                  system.out.print('[');                 while(k!=null){                     if(k.next!=null)                         system.out.print(k.data()+",");                      else                         system.out.print(k.data());                     k=k.next();                  }                    system.out.print(']');               }            }      class assignment9{          public static void main(string[]args){              reader r1 =  new reader();             r1.add('r');             r1.add('e');             r1.add('l');              r1.add('l');             r1.add('o');             r1.display();           }     } 

just cast char

system.out.print((char)k.data()+",");

and

system.out.print((char)k.data());

you can use int here have, best use appropriate type each variable in case char


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -