what this method does
Posted: Sat Feb 17, 2018 11:51 pm
hi all,
i have 2 question :
1)what does the method "what " below does and if you can explain me each line will be awsome..
2)how can i write the main and test it,like input a alist abd test this method
public class IntNode{
private int _data;
private IntNode _next;
public IntNode (int data){
_data = data;
_next = null;
}
public static boolean what(IntNode node){
IntNode t = node;
IntNode h = node._next;
int sum = 0;
boolean ok = false;
if(t != null)
sum = t._data;
while(h != null)
{
if(sum != h.data)
return false;
sum += h.data;
t = h;
h = h._next;
}
return true;
}
}
i have 2 question :
1)what does the method "what " below does and if you can explain me each line will be awsome..
2)how can i write the main and test it,like input a alist abd test this method
public class IntNode{
private int _data;
private IntNode _next;
public IntNode (int data){
_data = data;
_next = null;
}
public static boolean what(IntNode node){
IntNode t = node;
IntNode h = node._next;
int sum = 0;
boolean ok = false;
if(t != null)
sum = t._data;
while(h != null)
{
if(sum != h.data)
return false;
sum += h.data;
t = h;
h = h._next;
}
return true;
}
}