Program in Java to add two numbers using Scanner class

 AdditionScanner.java

package addition.scanner;

import java.util.Scanner;

public class AdditionScanner {   

    public static void main(String[] args) {

        int a,b,c;

        Scanner sc=new Scanner(System.in);

        System.out.println("Enter any two numbers to add");

        a=sc.nextInt();

        b=sc.nextInt();

        c=a+b;

        System.out.println(a +" + "+ b + " = " + c);

    }   

}


Output:



No comments:

Post a Comment