Input/Output
Arrays
Error handling
100
Asking the user to enter information that you are asking for.

What is prompting?

100

What does the following code produce?

Array[] = new int[5];

Error

Array is not a type and there is no class we can make an array of objects with.

100

What is the difference between error and exepction in java?

Errors are caused by the environment (JVM).

Exceptions are caused by the program itself.

200

What will the following code output?

for (int i = 10; i > 0; i--) {

System.out.println(i);

}

Output numbers 10-1 line by line.

200

What will the following code output?

int array[] = new int[] { 54, 2 };

for (int i : array) {

     System.out.println(i);

}

54

2

200

Will the code compile?

if (true) {

break;

}

Error

Break statements can only be used with loops or switch statements.

300

What will the following code output?

for (int i = 0; i > 0; i++) {

     System.out.println(i);

}

Nothing.

int i = 0 so the condition i > 0 is never true

300

What does the following code output?

int array[] = new int[] { 8, 2, 123, 2, 5, 3, 5 };

Arrays.sort(array);

for (int i : array) {

    System.out.println(i);

}

2, 2, 3, 5, 5, 8, 123

300

Will the code compile?

 public static void main(String[] args) {

        FileReader reader = new FileReader("test.txt");

        BufferedReader read = new BufferedReader(reader);

        String line = "";

        while ((line = read.readLine()) != null){

            System.out.println(line);

        }

        reader.close();

        read.close();

    }

Error, no FileNotFoundException or IOException has been thrown.

400

What will the following code output?

System.out.println('j' + 'a' + 'v' + 'a');

Outputs 418

418 = 106 + 97 + 118 + 97

400

What does the following code output?

int[][] matrix = new int[][] {

 { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 }

 };

System.out.println(

matrix[matrix.length - 3][matrix.length - 2]

);

2

400

Will the code compile?

int array[] = new int[] { 1, 3 };

   for (int i = 0; i < 3; i++) {

       System.out.println(array[i]);

    }

It will compile because the ArrayIndexOutOfBoundsException will occur after the program executes.

500

What will the following code output?

BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

int value = reader.readLine(); 

System.out.println(value);

Error

reader.readLine() returns a String so we must convert it to an int with Integer.parseInt(reader.readLine());

500

What will the new matrix look like?

int[][] matrix = new int[][] {

{ 8, 4, 3 }, { 1, 12, 6 }, { 7, 8, 9 }

};

Arrays.sort(matrix, (a, b) -> a[0] - b[0]);

8 4 3  

1 12 6 

7 8 9 

1 12 6 

7 8 9  

8 4 3  

500

Is there any error with the code?    

public static void main(String[] args) {

        System.out.println("Num " + recursion(1));

    }

    public static int recursion(int num) {

        if (num == 0) {

            return num;

        } else {

            return recursion(num++);

        }

    }

StackOverFlow error as the recursive case never reaches its base case.

M
e
n
u