#iterator issue

1 messages · Page 1 of 1 (latest)

stoic krakenBOT
#

<@&987246399047479336> please have a look, thanks.

stoic krakenBOT
#

While you are waiting for getting help, here are some tips to improve your experience:

Code is much easier to read if posted with syntax highlighting and proper formatting.

If nobody is calling back, that usually means that your question was not well asked and hence nobody feels confident enough answering. Try to use your time to elaborate, provide details, context, more code, examples and maybe some screenshots. With enough info, someone knows the answer for sure.

Don't forget to close your thread using the command </help-thread close:1027500463647621170> when your question has been answered, thanks.

craggy shell
#

whats ur question?

stoic krakenBOT
#

iterator issue

#

Changed the title to iterator issue.

tough shale
craggy shell
#

whats happening

#

dont just dump some random code and hope that someone will pick it up and execute it, understand whats wrong and then tell u a fix

#

u have to make it easy to help u

#

guide us through it

#

explain whats going on

#

explain what the issue is

#

explain whats unclear to u

#

put in some effort

tough shale
#

import java.util.*;

interface Iterator{
public boolean has_next();
public Object get_next();
}

class Sequence{
private final int maxLimit = 80;
private SeqIterator _iter = null;
int[] iArr;
int size;
Sequence(int size){
this.size = size;
}
//implement addTo(elem) to add an int elem to the sequence
public void addTo(int elem){
iArr[iArr.length - 1] = elem;
}
//implement get_Iterator() to return Iterator object
public Iterator get_Iterator(){
return iArr;
}
private class SeqIterator implements Iterator{
int indx;
public SeqIterator(){
indx = -1;
}
//implement has_next()
public boolean has_next(){
indx = indx + 1;
if(indx <= size-1){
return true;
}
else{
return false;
}
}
//implement get_next()
public Object get_next(){
//do stuff
}
}
}

class FClass{
public static void main(String[] args) {
Sequence sObj = new Sequence(5);
Scanner sc = new Scanner(System.in);
for(int i = 0; i < 5; i++) {
sObj.addTo(sc.nextInt());
}
Iterator i = sObj.get_Iterator();
while(i.has_next())
System.out.print(i.get_next() + ", ");
}
}