Results 1 to 9 of 9
  1. #1
    TeacherZ is offline Member
    Join Date
    Feb 2017
    Posts
    24
    Rep Power
    0

    Default 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();
    
    }
    }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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 **

  3. #3
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default 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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  4. #4
    TeacherZ is offline Member
    Join Date
    Feb 2017
    Posts
    24
    Rep Power
    0

    Default 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...

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    13,541
    Rep Power
    26

    Default 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 **

  6. #6
    TeacherZ is offline Member
    Join Date
    Feb 2017
    Posts
    24
    Rep Power
    0

    Default 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.

  7. #7
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default Re: Unexpected pause in program

    Quote Originally Posted by TeacherZ View Post
    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...
    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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  8. #8
    TeacherZ is offline Member
    Join Date
    Feb 2017
    Posts
    24
    Rep Power
    0

    Default 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

  9. #9
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    6,226
    Rep Power
    13

    Default 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,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. ActionListener: No pause/program keeps running?
    By pakupakuman in forum New To Java
    Replies: 1
    Last Post: 11-13-2012, 04:33 PM
  2. Pause the program and Start
    By ki_ha1984 in forum New To Java
    Replies: 12
    Last Post: 04-17-2012, 10:55 PM
  3. is there a way to pause java?
    By zhangster in forum New To Java
    Replies: 4
    Last Post: 04-24-2010, 07:38 PM
  4. How to pause
    By ravjot28 in forum Threads and Synchronization
    Replies: 0
    Last Post: 03-31-2010, 06:09 AM
  5. Help with Pause
    By trill in forum Java Applets
    Replies: 2
    Last Post: 09-28-2007, 08:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •