Spot the Errors: Reading and Summing Integers

Report a typo

Consider the following Java program snippet, which is intended to read two integers and output their sum. Identify the errors that might cause the program to fail:

import java.util.Scanner;

public class SumIntegers {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int num1, num2;

        System.out.println(Fill in these two numbers:);
        num1 = input.next();
        num2 = input.nextInt();

        int sum = num1 + num2;
        System.out.println(The sum is: + sum);
    }
}
Select one or more options from the list

Create a free account to access the full topic