How to add two numbers in Java Programming [closed]

You need to use the nextInt(); so something like:

public static void main(String[] args) {
    // TODO Auto-generated method stub


    System.out.println("First number: ");
    Scanner input = new Scanner(System.in);

    int x = input.nextInt(); 

    System.out.println("Second number: ");
    int y = input.nextInt();  

    int sum = x+y;

    System.out.println("Result: "+sum); 
}

Leave a Comment