0

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

5
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by Antenka
0

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 topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.