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.
|
Newbie Member
|
|
| 21Apr2011,16:21 | #2 |
|
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. |
|
Newbie Member
|
|
| 21Apr2011,16:25 | #3 |
|
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 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);
}
}
what i posted just to explain my problem where is it. =) |
