"KEEP LEARNING, DON'T STOP."
"KEEP LEARNING, DON'T STOP."
In this section you will learn how to add two numbers in java in easy way. We are performing simple arithmetic operation to add two numbers and then we will show result on output screen.
In this program we are taking the input from the user. We are using scanner function to take the input from user. To take the input from user we will import scanner package in our program.
Scanner function is use to take the input from user in java.
import java.util.Scanner; class addition { public static void main(String arg[]) { int a, b, c; Scanner sc = new Scanner(System.in); System.out.println("ENTER THE FIRST NUMBER:-"); a = sc.nextInt(); System.out.println("ENTER THE SECOND NUMBER:-"); b = sc.nextInt(); c = a+b; System.out.println("RESULT IS:- "+c); } }
ENTER THE FIRST NUMBER:- 10 ENTER THE SECOND NUMBER:- 5 RESULT IS:- 15
Advertisment