Lab 3b: Java Errors





Error Types


Syntax and Compile-Time Errors : Easy to locate and fix because the compiler usually provides diagnostics telling you exactly where they are.

Run-Time Errors and Logic Errors: An error is called a Run-Time error when it occurs after the program has successfully been compiled. Logic errors can be difficult to detect. The program will compile and execute without signalling any problems because Logic errors exist in the algorithm itself.



Each of the following programs has an error. Identify the error.



  1. int X = 98765434 * 987654345 *987654323;


  2. int x = 6;
    int y = 3;
    x = x * y / (x % y);


  3. double a = 3; double b = 4; double x = Math.sqrt(a - b);


  4. int a = 2;
    int b = 4;
    double x = (double ) (27 / (a / b));


  5. int n = 200000000;
    n *= n;
    n *= n;



  6. float a = 2.0f;
    float b = 4.5f;
    float c = 5.2f; float average = a + b + c / 3;