hello every body, how are you all
please i want some one to help me in my prgram this ,as i think, is the piece where the problem occur,
the output is being to give only the last value i enter from the keboard
where me need is to insert many values of ip and for each one i need a hop count and mask
public static void insertfirst(table tt)
{
int intstate, mask, hop;
long longip;
Scanner keyboard = new Scanner(System.in);
//BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String strip;
strip="11";
do
{
System.out.println("Enter IP address");
/*try{strip=br.readLine();
}
catch(IOException e) {
e.printStackTrace();
}*/
strip = keyboard.nextLine();
longip = conv.ip2long(strip);
System.out.println("Enter Mask");
String strmask;strmask="11";
/* try{strmask=br.readLine();
}
catch(IOException e) {
e.printStackTrace();
}*/
strmask = keyboard.nextLine();
mask = Integer.parseInt(strmask);
System.out.println("Enter Hop count");
String strhop;strhop="11";
/* try{strhop=br.readLine();
}
catch(IOException e) {
e.printStackTrace();
}*/
strhop = keyboard.nextLine();
hop = Integer.parseInt(strhop);
tt.inserthop(longip,hop,mask);
System.out.println("Are you want to insert a new element:"+"\t"+"1 for OK"+"\t"+"0 for stop");
String state;state="1";
/* try{state=br.readLine();
}
catch(IOException e) {
e.printStackTrace();
}*/
state = keyboard.nextLine();
intstate=Integer.parseInt(state);
}
while(intstate==1);
}
here is what output to me
Enter IP address
10.0.0.0
Enter Mask
25
Enter Hop count
123
Are you want to insert a new element: 1 for OK 0 for stop
1
Enter IP address
10.0.0.1
Enter Mask
26
Enter Hop count
134
Are you want to insert a new element: 1 for OK 0 for stop
1
Enter IP address
10.0.0.2
Enter Mask
27
Enter Hop count
234
Are you want to insert a new element: 1 for OK 0 for stop
0
Are you want to display the table: 1 for all table 2 for specified IP 0 for continue
1
IP is 10.0.0.0 Hop count is 234 Mask is 27
Are you want to display the table: 1 for all table 2 for specified IP 0 for continue
2
Enter the IP
10.0.0.1
Hop count is: 234
Are you want to display the table: 1 for all table 2 for specified IP 0 for continue
and here is the inserthop function
void inserthop(long add, int hop, int mask)
{
int flag =0;
for (int i =0; i<M.m; i++)
if ((this.t[i] != null) && ((this.t[i].add & 0xffffff00) == (add & 0xffffff00)))
{insertaddhop(t[i], add,mask,24,hop);
flag=1;
break;
}
if (flag==0)
for (int i =0; i<M.m; i++)
if (t[i] == null)
{
t[i]=new node();
insertaddhop(t[i], add,mask,24,hop);
break;
}
}
thank you very much in advance for any help
best regards