How to add two number in java by keyboard
import java.util.*;
public class Add
{
public static void main(String args[])
{
int a,b;
Scanner sc=new Scanner(System.in);
System.out.println("Enter two number");
a=sc.nextInt();
b=sc.nextInt();
c=a+b;
System.out.println("The Sum of two number is "+c);
}
}
output:
Entre two number
10
20
The Sum of two number is 30
here we are use the scanner class for taking the input by keyboard.
import java.util.*;
public class Add
{
public static void main(String args[])
{
int a,b;
Scanner sc=new Scanner(System.in);
System.out.println("Enter two number");
a=sc.nextInt();
b=sc.nextInt();
c=a+b;
System.out.println("The Sum of two number is "+c);
}
}
output:
Entre two number
10
20
The Sum of two number is 30
here we are use the scanner class for taking the input by keyboard.
No comments:
Post a Comment