Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

import java.util.Scanner;/* * To change this license header, choose License Head

ID: 3786314 • Letter: I

Question

import java.util.Scanner;/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package addition;

/**
*
* @author Hello
*/
public class Addition {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        Scanner input= new Scanner (System.in);
        int number1;
        int number2;
        int sum;
      
        System.out.print("Enter first integer:");
        number1=input.nextInt();
        System.out.print("Enter second integer:");
        number2=input.nextInt();
      
        sum=number1+number2;
        System.out.printf("sum is %d ", sum);
    }
  
}

This is the exact error message: I just want it to run

run:
Error: Could not find or load main class addition.Addition
C:UsersHelloAppDataLocalNetBeansCache8.1executor-snippets un.xml:53: Java returned: 1
BUILD FAILED (total time: 0 seconds)

Explanation / Answer

Hi

There is a compile time error in code. Package secion should be mentioned first in the code. I see ou imported Scanner class is in first place. The first section should be package.

I have modified the code. Please find the below updated code.

Addition.java

package addition;
import java.util.Scanner;/*

* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/**
*
* @author Hello
*/
public class Addition {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Scanner input= new Scanner (System.in);
int number1;
int number2;
int sum;
  
System.out.print("Enter first integer:");
number1=input.nextInt();
System.out.print("Enter second integer:");
number2=input.nextInt();
  
sum=number1+number2;
System.out.printf("sum is %d ", sum);
}
  
}

Output:

Enter first integer:2
Enter second integer:3
sum is 5