Please help me with a simple watch program.
In the program,I have to display on the same line.
i have written the following code which is not working.
pls look into it

class watch
{
	private int h,m,s,a=0,b=0;

	public void calc()
	{
		
		for(;a==b;s++)
		{
			if(s%60==1)
			{
				m++;
			}

			if(m%60==1)
			{
				h++;
			}

			System.out.println(h+" : "+m+" : "+s);

			Thread.getThread().sleep(1000);
		}

	}
	public static void main(String args[])
	{
		watch w1=new watch();
		w1.calc();
	}

}

The highlighted statement gives an error.
pls help me with the logic of displaying it on the same line.
thanks

Recommended Answers

All 4 Replies

Let me guess "un-catch exception". Put that section in try/catch exception and catch InterruptedException (API)

Rather I would say the error is from calling methods that do not exist on the Thread class.

first of all, what is the value of variable (s) here in the program, it is assumed here as it is zero , is it the value that you want it or not

secondly the looping will be infinite because value of variable (a) and value of variable (b) is always same , therefore check it again to make the loop finite

hope it helps
thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.