943,936 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Unsolved
  • Views: 510
  • Java RSS
Dec 5th, 2008
0

help with watch program

Expand Post »
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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
shubhang is offline Offline
25 posts
since Oct 2008
Dec 5th, 2008
0

Re: help with watch program

Let me guess "un-catch exception". Put that section in try/catch exception and catch InterruptedException (API)
Last edited by peter_budo; Dec 5th, 2008 at 2:08 pm. Reason: add link
Moderator
Featured Poster
Reputation Points: 2786
Solved Threads: 873
Code tags enforcer
peter_budo is offline Offline
6,656 posts
since Dec 2004
Dec 5th, 2008
0

Re: help with watch program

Rather I would say the error is from calling methods that do not exist on the Thread class.
Moderator
Featured Poster
Reputation Points: 3239
Solved Threads: 839
Posting Genius
Ezzaral is offline Offline
6,761 posts
since May 2007
Dec 6th, 2008
0

Re: help with watch program

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
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
alsoumhi is offline Offline
66 posts
since Aug 2007
Dec 6th, 2008
0

Re: help with watch program

Hello, shubhang.
You've asked:
Quote ...
pls help me with the logic of displaying it on the same line.
Here is a few articles about positioning cursor in console application:
http://mindprod.com/jgloss/console.html
http://en.allexperts.com/q/Java-1046...or-console.htm
http://www.rgagnon.com/javadetails/java-0469.html
Hope it can help
Last edited by Antenka; Dec 6th, 2008 at 3:26 pm.
Reputation Points: 293
Solved Threads: 82
Posting Whiz
Antenka is offline Offline
361 posts
since Nov 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: NetBeans and MYSQL
Next Thread in Java Forum Timeline: java ping





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC