

public class final1 {
	
	public static void main (String[] args)
	{
		int a = 0;
		int b = 10;
		Range R = new Range(a,b);
		new Thread ("Range").start();		
	}
}
class Range implements Runnable
{
int low, high;
boolean valueset = false;
int n;
IteratorHelper ih = new IteratorHelper(null);
public Range(int a, int b) 
{
	this.low = a;
	this.high = b;
	new Thread(this, "Range").start();
}
public boolean hasNext()
{
return ih.done(); 
}
public int next()
{
return ih.get();
}
public void run() {
for (int i = low; i<high; i++)
{
	ih.yield(i);
}
}
}
class IteratorHelper 
{
Range R;
int j = 0;
public IteratorHelper (Runnable r)
{ 
	this.R = (Range) r;
	}

synchronized public void yield(int i)
{
	boolean valueset = false;
	int n=0;
	if (!valueset)
	{
		try
		{
			wait();
		}
		catch (InterruptedException e)
		{
			System.out.println("InterruptedException caught");
		}
		this.j = n;
		valueset = true;
		System.out.println("Print:"+n);
		notify();
	}
	
}
synchronized int get() 
{ 
	boolean valueset = false;
	int n =0;
if(!valueset) 
try { 
wait(); 
} catch(InterruptedException e) { 
System.out.println("InterruptedException caught"); 
} 
System.out.println("Print: " + n); 
valueset = false; 
notify(); 
return n; 
} 
public boolean done()
{
	if (j == 0)
	return false;
	return false;
	
}	
	}