go to previous page   go to home page   go to next page hear noise

Answer:

Line number 11.

Although your source code is translated from text into bytecodes, and it is the bytecodes that are executed by the Java virtual machine, the file of bytecodes EchoSquare.class retains some line number information which is displayed when your program crashes.


Another Example

Here is another example. It asks the user for two integers which are then added together and the sum written out.

import java.util.Scanner;

class AddTwo
{
  public static void main (String[] args) 
  { 
    Scanner scan = new Scanner( System.in );
    int first, second, sum ;      // declaration of int variables

    System.out.println("Enter first  integer:");
    first = scan.nextInt();       // read chars and convert to int

    System.out.println("Enter second integer:");
    second = scan.nextInt();      // read chars and convert to int

    sum = first + second;         // add the two ints, put result in sum

    System.out.println("The sum of " + first + " plus " + second +" is " + sum );
  }
}

Here is a sample run:

Enter first  integer:
12
Enter second integer:
-8
The sum of 12 plus -8 is 4

QUESTION 16:

(A slightly hard question: ) explain what happened in the following run of the same program:

Enter first  integer:
12 -8
Enter second integer:
The sum of 12 plus -8 is 4