Results 1 to 9 of 9
Thread: Unexpected pause in program
- 03-08-2017, 07:43 AM #1
Member
- Join Date
- Feb 2017
- Posts
- 24
- Rep Power
- 0
Unexpected pause in program
I have a working piece of code.
The problem is when I define a method for System.in the program pauses there.
WHen the program pauses, I get this message in the console window:
"Listening for transport dt_shmem at address: jdbconn"
I have put a comment at the place where the program pauses. After I click continue
within the editor/debugger the program runs as designed giving me the proper output.
What I do not understand is why is this program stopping?
I'm really not doing anything fancy - I'm actually incapable of fancy coding
at this stage. Any suggestions?
Thanks!
THe code is below
Java Code:import java.util.Scanner; public class FermatCheck { boolean fermat; double sum; double difference; void fermat(){ if (fermat) { System.out.println("Fermat was right - this time!"); } else { System.out.println("Fermat was Wrong!!!"); } } public double sum(double a, double b, double n) { sum = Math.pow(a,n) + Math.pow(b,n); return sum; } public double difference(double c, double n, double sum) { difference = Math.pow(c,n) - sum; return difference; } public static void main(String args[]) { System.out.println("Fermat Test\n"); System.out.println("Enter a, b, c and their common exponent\n"); Scanner scan = new Scanner(System.in); // this is where the program pauses double a = scan.nextDouble(); double b = scan.nextDouble(); double c = scan.nextDouble(); double n = scan.nextDouble(); FermatCheck Check = new FermatCheck(); System.out.println("The sum of a^n and b^n is " + Check.sum(a,b,n)); System.out.println(""); System.out.println("The difference between c^n ( c ) and a^n+b^n is " + Check.difference(c,n,Check.sum)); if (Check.difference(c,n,Check.sum) > 0) { Check.fermat = true; } else { Check.fermat = false; } Check.fermat(); } }
- 03-08-2017, 10:15 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Unexpected pause in program
If it is entering the debugger then you are debugging the program and not running it...and you have a breakpoint on the line.
Please do not ask for code as refusal often offends.
** This space for rent **
- 03-08-2017, 08:07 PM #3
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Unexpected pause in program
I am curious if this is for a class. I ask because testing Fermat's theorem, which has been proven correct, doesn't allow you
to find examples of failure (i.e. line 15 above will never execute as long as precision is maintained). Note: even if Fermat's
theorem wasn't proven, you would never find failure in any reasonable time frame.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 03-09-2017, 06:07 AM #4
Member
- Join Date
- Feb 2017
- Posts
- 24
- Rep Power
- 0
Re: Unexpected pause in program
Tolls:
You were half right. Java-Editor inserted a break point (transparent in the GUI until the program ran.
When I selected the show break points it landed where my code stopped.
I cleared the break point and the program runs without interruption.
I still do not know why this occurred as I am only using compile and run.
Maybe fat fingers hit a key combination... SOrry for wasting your time...
Jim,
THe code is meaningless in that Fermat's theorem has been proven true.
THis is just a vehicle for me to learn java.
I know, unless I use values for a right triangle the program should always prove Fermat was right.
Probably dumb, but it helps me to explore on my own and follow tutorials.
I need to make my own mistakes to learn completely...
- 03-09-2017, 10:31 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 13,541
- Rep Power
- 27
Re: Unexpected pause in program
Does your editor always execute in debug mode then?
That seems a bit unusual.Please do not ask for code as refusal often offends.
** This space for rent **
- 03-09-2017, 12:12 PM #6
Member
- Join Date
- Feb 2017
- Posts
- 24
- Rep Power
- 0
Re: Unexpected pause in program
This is the first time I have seen this. That is what confused me.
And this occurred only in this program. I'm going to call this fat fingers and
ignore finding a cause unless it happens again.
- 03-09-2017, 03:40 PM #7
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Unexpected pause in program
I understand. If you want to try to program some other interesting things here are a few.
1. Take any number with even number of digits and demonstrate the following:
For n = abcd (four digits) find solutions for
(ab + cd) *(ab + cd) = abcd
Note: This can also be derived using number theory.
2. Find Armstrong numbers. For a number q of n digits,
raise each digit to the nth power and add to see if it equals q.
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
- 03-14-2017, 06:52 PM #8
Member
- Join Date
- Feb 2017
- Posts
- 24
- Rep Power
- 0
Re: Unexpected pause in program
Jim,
I took your advice and tried to program the first problem.
You are saying for a collection of 4 digits - abcd that make up a 4-place number,
there are some collections of a, b, c and d such that (a*b + c*d)*(a*b + c*d) = abcd.
I wrote the program and there were no numbers that met this condition.
It was a simple brute force search from 1000 to 9999, evaluating every number
per the formula. I did debug this - my numbers changed monotonically from 1000 to 9999.
The difference between (ab+cd)*(ab+cd) - (1000*a + 100*b + 10*c + d) changed and corresponded
to what I could calculate with a numerical calculator.
As this is getting off topic of true java learning, can you tell me if the condition I am coding is correct?
I will send code if you are interested, but worry about protocol here on this site.
Thanks!
Mark
- 03-14-2017, 11:43 PM #9
Senior Member
- Join Date
- Jan 2013
- Location
- Northern Virginia, United States
- Posts
- 6,226
- Rep Power
- 15
Re: Unexpected pause in program
Here is an example. Think of the number 2934
29 + 34 = 63.
if (63 * 63 == 2934) { // which it doesn't
// you would have found a solution
}
Consider 219392
219 + 392 = 611
does 611 * 611 == 219392 ?
Regards,
JimThe JavaTM Tutorials | SSCCE | Java Naming Conventions
Poor planning on your part does not constitute an emergency on my part
Similar Threads
-
ActionListener: No pause/program keeps running?
By pakupakuman in forum New To JavaReplies: 1Last Post: 11-13-2012, 05:33 PM -
Pause the program and Start
By ki_ha1984 in forum New To JavaReplies: 12Last Post: 04-17-2012, 11:55 PM -
is there a way to pause java?
By zhangster in forum New To JavaReplies: 4Last Post: 04-24-2010, 08:38 PM -
How to pause
By ravjot28 in forum Threads and SynchronizationReplies: 0Last Post: 03-31-2010, 07:09 AM -
Help with Pause
By trill in forum Java AppletsReplies: 2Last Post: 09-28-2007, 09:50 PM
Bookmarks