Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
  • salvin francis
  • fred rosenberger
  • Frits Walraven

Program Hangs and is unresponsive with cursor blinking in console

Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Developed a solution[] to one of the challenges given in the following site:

While giving input as attached [Input.txt], the program hangs and the cursor keeps blinking in console.

Can anyone please help figure why is this happening?

while providing smaller values as input, correct output is seen. For example:
3 3 3
1 2 3
2 4 6
0 0 1 1
0 0 2 2
1 1 2 2

Master Rancher
Posts: 887
Netbeans IDE Oracle MySQL Database Tomcat Server C++ Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I have not put this in my NetBeans and took it for a spin, but one of the first things that I notice is that everything is static.  The next thing I notice is:

At the point you initialize st, br is not guaranteed to have anything to read.

Posts: 69065
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . and why are you using StringTokenizer at all? Have you read its documentation?
Saloon Keeper
Posts: 3923
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Mary,

I have not run your program, but I take it from you that your code is working for small input arrays.

According to the specs of that exercise, the sizes of the two arrays can be 10^5, so if you get such arrays, and r1, r1 , c1 and c2 are 1 and max (and knowing HackerRank a little, I'm sure they will give you these) that means that you are trying to calculate 10^10 gcd's, and that number is way too large to calculate them all. You can test whether that is the problem, just add to your 'calGCDSubMatrix' method some print statements, for instance what r1, c1, r2 and c2 are, and the number of the calculations that must be performed ((r2 - r1 + 1) * (c2 - c1 + 1)), and print out, say, every 1000th of these calculations. That gives you an idea how fast it goes.

At least you can see if your code is still running, and how long that submatrix will be going to take.
Posts: 7080
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've executed your program and it finishes without error.  To confirm that the program is completed, try adding a Sysout.out.println() to the end of the main() method:
This was the output I got:
Our first order of business must be this tiny ad:
ScroogeXHTML 8.7 - RTF to HTML5 and XHTML converter
    Bookmark Topic Watch Topic
  • New Topic