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

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

This article has been dead for over six months. Start a new discussion instead.