adsense

Hii, welcome to my site. My name is Om prakash kartik. This blog helps you to learn programming languages concepts.

Program in Java to add two numbers

Program in Java to add two numbers

import java.util.Scanner; 
class AdditionDemo
{
 public static void main(String []args)
  {
	 //Input data from keyboard
         Scanner cin = new Scanner(System.in);
	 System.out.print("Enter two integer numbers :- ");
	 int x = cin.nextInt();
	 int y = cin.nextInt();
	 int sum = x + y;
	 System.out.println("Sum = "+sum);
	 //Without using third variable
	 System.out.println("Sum of two integer numbers = "+(x + y));
	 
	 System.out.print("\nEnter two floating point numbers :- ");
	 float a = cin.nextFloat();
	 float b = cin.nextFloat();
	 System.out.println("Sum of two floating point numbers = "+(a + b));
  }
}

Output :-









Post a Comment

0 Comments