Add Two Numbers In Java Taking Input from User - Math Traders

Latest

Add Two Numbers In Java Taking Input from User

Hello friends in this tutorial i shall tell you how that how you take input from the user in Java programming language and add two numbers by taking input from the user in Java.

To take input form the user In java we use a "Scanner" function which we import under a Java Package and the syntax for this Java Package is "import java.util.*;" then we create a scanner class in java. For better Understanding let us now see we use "Scanner" into a java program to take an input from the user.

so lets begin.


import java.util.Scanner;

public class userr {

public static void main(String[] args) {
int a,b,sum=0;
System.out.println("enter two integers");
Scanner kb = new Scanner(System.in);
a = kb.nextInt();
b = kb.nextInt();
sum=a+b;
System.out.println("sum of numbers is \t" +sum);
}

}

input a = 5 and b= 9 from the keyboard your program output will be :sum of numbers is 14

No comments:

Post a Comment