Reading problem

Discussion in 'Java' started by And Rew _ 2, Apr 21, 2011.

  1. And Rew _ 2

    And Rew _ 2 New Member

    Joined:
    Apr 21, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    hii

    am working in program i finished but i faced problem :

    the file that i want to read it is like this

    2 2

    2 5

    4 9

    0 0


    my code is


    Code:
    public static void main(String[] args) { try { Scanner read = new Scanner(new File("file.in")); while(read.hasNext()) { ?????????????? } myLinkedList LL = new myLinkedList (); for(int i=1;i<=t;i++) { LL.addLast(i); } LL.remove(s); } // catch catch(Exception e) { System.out.println(e); } }

    look when i put s and t !

    s is : 2 2 4
    t is : 2 5 9

    and stop reading when it is reach the 0 // i have no problem with this step
    but what am stack in is how i can read file as the way i explained.
    because this step is what i need to finish my project.
     
  2. And Rew _ 2

    And Rew _ 2 New Member

    Joined:
    Apr 21, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    If you do not get the idea i will try to explain it more :

    the program should read the file " input file" which has two columns s , and t.
    every time the program read a value of t. it will put it in the for loop :
    for(int i=1;i<=t;i++) // so t will change until reach 0 and program will stop.
    so if it read
    2 --> for(int i=1;i<=2;i++) .. so the size of linked list will be 2
    6--->for(int i=1;i<=6;i++) ......................................... 6
    9--->for(int i=1;i<=9;i++) ......................................... 9

    and the same thing for remove method
    the program should read the value s and put it here
    LL.remove(s);
    first time
    LL.remove(2);
    and then
    LL.remove(2);
    then
    LL.remove(4);

    also when reached 0 will stop ! the two implementations will happen at the same time
    but i have no idea how to do that.
     
  3. And Rew _ 2

    And Rew _ 2 New Member

    Joined:
    Apr 21, 2011
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    Code:
        public static void main(String[] args) {
    
            try
            {
            Scanner read   =  new Scanner(new File("file.in"));
            while(read.hasNext())
                {
               ??????????????
                }
            myLinkedList LL = new myLinkedList ();
                    
                        for(int i=1;i<=t;i++)
                            {
                                    LL.addLast(i);
                            }
                            LL.remove(s);
    
                     
    
            }
           
            // catch
                    catch(Exception e)
            {
                System.out.println(e);
            }
    
        }
    
    
    
    This the code , i could not edit in the first post , this not compile just to explain the idea.



    this one is compile and work when i put the value of s and t by myself
    Code:
        public static void main(String[] args) {
    
            try
            {
            Scanner read   =  new Scanner(new File("file.in"));
      
            myLinkedList LL = new myLinkedList ();
                    
                        for(int i=1;i<=9;i++)
                            {
                                    LL.addLast(i);
                            }
                            LL.remove(4);
    
                     
    
            }
           
            // catch
                    catch(Exception e)
            {
                System.out.println(e);
            }
    
        }
    
    It is compile and work !
    what i posted just to explain my problem where is it. =)
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice